This is my model with Country And Brand entities.
I'm trying to get all brands with specified country name. Code looks like this:
var brands: [Brand]!
let brandRequest = Brand.createFetchRequest()
brandRequest.predicate = NSPredicate(format: "country.name == %@", countryName!)
if let fetchedBrands = try? container?.viewContext.fetch(brandRequest) {
if fetchedBrands!.count > 0 {
brands = fetchedBrands!
}
}
Everything is in database. Brands and Country are related properly, but fetchedBrands is "nil".
What am I doing wrong ?