Reputation: 4254
I'm trying to find a way to store a CGPoint in a Core Data db.
After googling around I found somewhere that one way to do it would be to have an Entity (Point2D in my case) with x and y attributes. Both floats that get mapped to NSNumber.
The problem is that in order to get the point back I have the following method of my Point2D NSManagedObject sublass:
- (CGPoint) cgPointValue {
return CGPointMake([self.x floatValue], [self.y floatValue]);
}
And it works, but as I have a lot of points it seems to be hogging the CPU.
I wonder if there's a more efficient way to do this.
Upvotes: 1
Views: 2486
Reputation: 4932
I think there is no way to save some CPU time in this case, event with code below, it will do same thing, maybe less maybe more:
// >>> Saving result string int CoreData
CGPoint point = CGPointMake(20.0f, 20.f);
NSString *pointToSavae = NSStringFromCGPoint(point); // Will store string {20,20}
// >> Restoring point from string, retrieved from CoreData
CGPoint pointFromString = CGPointFromString(pointToSavae);
Upvotes: 8