0

I am writing an application using Core Data, with this attribute in one entity:
@property (nonatomic, retain) NSString * mesa;

I have a problem passing the value from a JSON processed dictionary:
local.mesa =[locales [0] valueForKey:@"mesa"];

I am obtaining this error:
'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "mesa"; desired type = NSNumber; given type = __NSCFString; value = Salón 2.'

This indicates to me that the desired type is NSNumber, but the attribute is declared as NSString in the xcdatamodel and the class.

It is possible that the first declaration of the attribute was NSNumber, and it seems as if he had not changed.

Any ideas?

Paco
  • 3
  • 3
  • 1
    make sure it is NSString in the model, then regenerate the NSManagedObject file. You shouldn't manipulate the core data generated NSmanagedObject files directly – William Falcon Apr 22 '13 at 16:25
  • 1
    also, if you changed the data type of an item in the model you should clean the build and delete any existing database file before running again. – Wain Apr 22 '13 at 16:36
  • Thanks, but how I can regenerate the NSManagedObject file?. I have cleaned and built the product, but i have not deleted any database – Paco Apr 22 '13 at 16:46
  • I solved it uninstalling the app from the simulator, and after, following this thread: http://stackoverflow.com/questions/12617585/cannot-create-an-nspersistentstorecoordinator-with-a-nil-model-after-deleting-ap recreating the right hierarchy of data model. Thanks everybody – Paco Apr 22 '13 at 20:49
  • What if the app is in app-store? User will just update the app and not delete it. How to resolve in this case? – Laxy Apr 23 '18 at 19:09

2 Answers2

1

If the schema had a nsnumber before in the simulator delete your app from the simulator so a new core database is created with nsstring in that variable.

ejkujan
  • 271
  • 1
  • 3
0

I forget to close this, sorry. Like I said before:

I solved it uninstalling the app from the simulator, and after, following this thread: Cannot create an NSPersistentStoreCoordinator with a nil model after deleting app from device recreating the right hierarchy of data model. Thanks again

Community
  • 1
  • 1
Paco
  • 3
  • 3