У меня есть базовая база данных с сущностями Post и Client.Сообщение имеет отношения «один ко многим».
У меня ошибка со строками self.addToClients(newClient)
:
ERROR Cannot invoke 'addToClients' with an argument list of type '(NSManagedObject)'
Определение двух моих сущностей:
public class Post: NSManagedObject {
@nonobjc public class func postFetchRequest() -> NSFetchRequest<Post> {
return NSFetchRequest<Post>(entityName: "Post")
}
@NSManaged public var id: NSNumber
@NSManaged public var content: String
@NSManaged public var clients: NSSet?
func insertClientFor(url:String, completion: @escaping(Bool) -> ()) {
let managedContext = CoreDataManager.sharedManager.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Client",in: managedContext)!
let newClient = NSManagedObject(entity: entity, insertInto: managedContext)
newClient.setValue(url, forKey: "url")
self.addToClients(newClient) //ERROR Cannot invoke 'addToClients' with an argument list of type '(NSManagedObject)'
do {
try managedContext.save()
completion(true)
} catch let error as NSError {
print("Could not save. \(error), \(error.userInfo)")
completion(false)
}
}
}
// MARK: Generated accessors for clients
extension Post {
@objc(addClientsObject:)
@NSManaged public func addToClients(_ value: Client)
@objc(removeImagesStripObject:)
@NSManaged public func removeFromClients(_ value: Client)
@objc(addImagesStrip:)
@NSManaged public func addToClients(_ values: NSSet)
@objc(removeImagesStrip:)
@NSManaged public func removeFromClients(_ values: NSSet)
}
@objc(Client)
public class Client: NSManagedObject {
@NSManaged public var url: String
@NSManaged public var post: Post
@nonobjc public class func fetchRequest() -> NSFetchRequest<ImageStrip> {
return NSFetchRequest<ImageStrip>(entityName: "ImageStrip")
}
}
Я не понимаю, что не так.