After the migration, one of my numerical values that are now zero, are visible as zero. If I do not migrate, the value retains its zero-zero value.
I first tried to set a number value in a managed object:
[temp setNumUses: temp.numUses + 1];
... but this caused an 'EXC_BAD_ACCESS' so I changed it to:
int hold = (int) [[Temp valueForKey : @ "Points"]] intValue]); Grab ++; [Temp setNumUses: [[NSNumber alloc] initWithInt: catch]];
... But after the migration, this code claims that the value of holds
0 was initialized as an integer, when the new Before the code ran its value was clearly 1 or more (referring to test object which only used 1 time).
When I do not migrate the Core Data Database, NSNM has kept its values properly through many references and the application terminates.
What am I missing? I have some extensive codes that modify the value of NSManagedObjects converted to a database stored in another location, but none of this tamper with 'numUses'
Thoughts?
The easiest description is that the migration somehow recognizes the core data numbers
A new feature with the default value of zero is due to the migration model and the assignment code you provided will not be in.
However, the code in parent suggests that you do not consider NSN in a lot and could be the cause of your problem from anywhere in place of NSNM.
NSN is only an object cover around numeric values. You can not do the operation with it This is the reason for this line:
[temp setNews: temp.numUses + 1];
... causes EXC_BAD_ACCESS
. As you found, you have to convert an NSNM to an int or NSDecimalNumber to perform mathematical operations on it.
This row:
[temp setNumUses: [[NSNumber alloc] initWithInt: hold]];
... will leak the memory you initialize an NSNumber object but never release it. In this case (and the vast majority of all cases), you need to create NSNumbers Class methods should be used because they return an autoresaled object that will not leak. Therefore:
[temp setNumUses: [nsnumber numberathel: hold];
In general, this is a poor practice to start any object in the law parameters. You are asking for bad memory leaks, which will be very difficult to track down. The leakage report can not be shown in the code where the method is called, but only in the law
Comments
Post a Comment