I have a small iOS application which relies on CoreData. I have at the moment two entities, "Product" and "StorageLocation". There is a one-to-many relationship between them. I generated the classes manually; the Model Editor also shows the correct class name.
When trying to save a new "Product" which contains a relationship to a "StorageLocation" I get this error:
-[StorageLocation addProductsObject:]: unrecognized selector sent to instance 0x60000389d280"
The generated NSManagedObject class is as follows:
import Foundation
import CoreData
extension StorageLocation {
@nonobjc public class func fetchRequest() -> NSFetchRequest<StorageLocation> {
return NSFetchRequest<StorageLocation>(entityName: "StorageLocation")
}
@NSManaged public var id: UUID?
@NSManaged public var name: String?
@NSManaged public var products: NSSet?
}
// MARK: Generated accessors for products
extension StorageLocation {
@objc(addProductsObject:)
@NSManaged public func addToProducts(_ value: Product)
@objc(removeProductsObject:)
@NSManaged public func removeFromProducts(_ value: Product)
@objc(addProducts:)
@NSManaged public func addToProducts(_ values: NSSet)
@objc(removeProducts:)
@NSManaged public func removeFromProducts(_ values: NSSet)
}
extension StorageLocation : Identifiable {
}
Problem, as error says, is the method "addToProducts" which I invoke like this:
let newItem = Product(context: viewContext)
newItem.id = id
newItem.name = name
newItem.qty = Int32(actualQty)
newItem.expDate = expDate
location.addToProducts(newItem)
I also checked if the model matches with the classes, no error found.
Any idea/hint?
Thanks Marco