Failed to save NSNumber in master data.

I am using Core Data in my application. I have an attribute called PINCode that has an Int64 property . Now, in my application, I take the PIN code from the text field, convert it to NSNumber and try to save as the attribute value for the object. But I can’t do it. The exception to this on the console is: - The application terminated due to the uncaught exception "NSInvalidArgumentException", reason: "The value type for the attribute is invalid: property =" PINCode "; desired type = NSNumber; this type = NSCFString; value = 121.

Here is the code: - (Convert to NSNumber): -

NSString *str= txtPINCode.text;
NSNumber *num = [[NSNumber alloc]init];
int tempNum = [str intValue];
num = [NSNumber numberWithInt:tempNum];

(Saving in the main data object): -

NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription insertNewObjectForEntityForName:@"MemberTable" inManagedObjectContext:context];
[newContact setValue:num forKey:@"PINCode"];

. . : -

NSNumber *testNumber = [[NSNumber alloc]init];
id test = num;
BOOL testMe = [test isKindOfClass:(Class)testNumber];

- ? .

+3
1

, . 2 NSNumber, 4 NSNumber 2 NSNumber ( ).

, , ? num ( 1) 2.

2 1 4 :

NSNumber *num = [[NSNumber alloc] initWithInt:tempNum];

.

0

Source: https://habr.com/ru/post/1783394/


All Articles