开发者

problem with NSManagedObject

开发者 https://www.devze.com 2023-03-21 00:19 出处:网络
I have a core data NSManagedObject named CD_CoffeeShop . When i allocated a variable CD_CoffeeShop *temp_CS = [ CD_CoffeeShop new]

I have a core data NSManagedObject named CD_CoffeeShop . When i allocated a variable

CD_CoffeeShop *temp_CS = [ CD_CoffeeShop new]

and try to pass a value to it,

[temp_CS setCoffeeShopId:[NSNumber numberWithInt:coffeeShop.Id]];

(the variable coffeeShopId of temp_CS is a NSNumber)

i get an error that says :

Terminating app due to uncaught exception 'NSInvalidArgumentException开发者_JAVA技巧', reason: '-[CD_CoffeeShop setCoffeeShopId:]: unrecognized selector sent to instance 0x6b34040'

What can it be ?


Have you read the Core Data Programming guide? You do not instantiate core data objects with the NSObject methods. You either obtain them with a fetch request if they exist already or you use NSEntityDescription to insert a new object into the context.

Definitely don't use new.

0

精彩评论

暂无评论...
验证码 换一张
取 消