Ich versuche, alle Modelle, die zu einer Marke gehören, aber wenn ich versuche, den Fremdschlüssel zu bekommen, bekomme ich einen NSSET-Typ mit einer Art von Adressstruktur, die Fremdschlüssel im Inneren haben mein Code, und ich bin mit dem stecken, hier ist:Fetch verwandte Tabellen in swift 3
class func insertNew (brandDescription: String, inManagedObjectContext context: NSManagedObjectContext) -> Car_Brand? {
let request: NSFetchRequest<Car_Brand> = Car_Brand.fetchRequest()
request.predicate = NSPredicate (format: "brand = %@", brandDescription)
if let brand = (try? context.fetch(request))?.first {
return brand
} else if let brand = NSEntityDescription.insertNewObject(forEntityName: "Car_Brand", into: context) as? Car_Brand {
brand.brand = brandDescription
return brand
}
return nil
}
class func fetchModel (brandDescription: String, inManagedObjectContext context: NSManagedObjectContext) -> [String]? {
let Brand = Car_Brand.insertNew(brandDescription: brandDescription, inManagedObjectContext: context)
let request: NSFetchRequest<Model> = Model.fetchRequest()
request.predicate = NSPredicate(format: "id_model = %ld", (Brand?.id_model)!)
request.propertiesToFetch = ["model"]
request.sortDescriptors = [NSSortDescriptor(key: "model", ascending: true)]
if let preModelList = try? context.fetch(request) as [Model] {
var modelList: [String] = []
for preModelList in preModelList {
modelList.append(preModelList.model!)
}
return modelList
} else {
return nil
}
}
können Sie mir zu verstehen, bitte helfen, wie verknüpfte Tabellen zu holen?
danken ist, nur ein, wenn nicht vorhanden, ich habe versucht, das Prädikat zu, so etwas zu ändern, request.predicate = NSPredicate (Format: "Car_Brand.id_model =% @", brandDescription), funktioniert aber auch nicht, weißt du, wo ich einige gute Beispiele finde, um auf diese Weise zu filtern –