X-Cake

Cocoaheads Ireland and Northern Ireland

Hey guys,

I have a wee but of a problem in regards to using CoreData in my project. One of the objects that i have created contains an array of NSNumbers but looking at the attribute types in the the data model there doesn't seem to be any NSArray type (I should have looked). Is there any way around this problem or am i going to have to extract all of these values and assign them to an object variables and then store them in the model?

Views: 111

Reply to This

Replies to This Discussion

You could always save it as Binary Data simply by converting it to NSData and then costing it back as you need it.
*casting / converting rather

Mick Walker said:
You could always save it as Binary Data simply by converting it to NSData and then costing it back as you need it.
This might be a bit overkill, but you could create a new object with a single NSNumber.

Then, in your current object create a one-to-many relationship to the new object type.
i got round this problem by converting the array of ints into a string separated by colons and then breaking them up again when i needed them.
For the record, I'm storing arrays in Core data no problems. Datatype in Core Data in Binary.

Save:
NSData *pointsAsData = [NSKeyedArchiver archivedDataWithRootObject:walkManager.locations];
[walkManager.route setValue:pointsAsData forKey:@"points"];

note: "walkManager.locations" is an NSMutableArray
"walkManager.route" is an NSManagedObject

Retrieve:
NSData* thePointsAsData = [walkManager.route valueForKey:@"points"];
NSArray* inProgressRoutePoints = [NSKeyedUnarchiver unarchiveObjectWithData:thePointsAsData];


Ok everyone, now guess what this app I'm working on does? ;-)

Reply to Discussion

RSS

© 2013   Created by Matt Johnston.   Powered by

Badges  |  Report an Issue  |  Terms of Service