0
votes

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', reason: '-[CD_CoffeeShop setCoffeeShopId:]: unrecognized selector sent to instance 0x6b34040'

What can it be ?

1
Have you declared setCoffeeShopId in the .h file? - MByD
they are declared dynamic, but also if i try to manually set it as temp_CS.coffeeShopId = [NSNumber numberWithInt:coffeeShop.Id]]; it won't work, it shows me the same error - Alex
is coffeeShopId synthesize? - MByD

1 Answers

3
votes

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.