I am using Core Data in my application.I have an attribute named PINCode which has property Int64. Now,in my app I take the PIN code from a text field,convert it into NSNumber and try to store as an attribute value for an entity.But I am unable to do so.The exception that it shows on the console is:- Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "PINCode"; desired type = NSNumber; given type = NSCFString; value = 121.'
Here is the code:- (Conversion to NSNumber):-
NSString *str= txtPINCode.text;
NSNumber *num = [[NSNumber alloc]init];
int tempNum = [str intValue];
num = [NSNumber numberWithInt:tempNum];
(Storing in core data entity):-
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription insertNewObjectForEntityForName:@"MemberTable" inManagedObjectContext:context];
[newContact setValue:num forKey:@"PINCode"];
The app crashes at this point.I am unable to find the reason of crash.I have also tried to check the conversion by the following code:-
NSNumber *testNumber = [[NSNumber alloc]init];
id test = num;
BOOL testMe = [test isKindOfClass:(Class)testNumber];
Can anybody help me with this?? Thanks in advance.
PINCode
toInt 32
? You shouldn't need the extra precision of 64 bits on a PIN code field, and the 32-bit iPhone processor might be representing the 64 bit type differently with Core Data. – Brad Larson[testNumber class]
for that. In any case, I'm not sure what you're trying to do with the type comparison. – Brad Larson