我有一个类Client,它映射在Core Data上。
class Client: NSManagedObject {
@NSManaged var firstName: String?
@NSManaged var lastName: String?
@NSManaged var age: Int?
我试图实现NSCopy,我写了这段代码
class Client: NSManagedObject, NSCopying {
@NSManaged var firstName: String?
@NSManaged var lastName: String?
@NSManaged var age: Int?
init(firstName: String, lastName: String, age: Int) {
self.firstName = firstName?
self.lastName = lastName?
self.age = age?
}
func copy(with zone: NSZone? = nil) -> Any {
let copy = Person(firstName: firstName, lastName: lastName, age: age)
return copy
}
}
但我从xcode收到错误
类型'客户'不符合协议'NSCopying'
是否缺少某些内容或是否有另一种解决方案旁边的解决方案来复制具有值的客户端对象?