I have an NSMutableArray with a bunch of Points(it's a class defined by me) inside. And I want to serialize this NSMutableArray to save to my disk. If I implement in my class Point the NSCoding protocol is it possible to use NSKeyedArchiver directly in my NSMutableArray?
Just like this example:
NSMutableData *data = [NSMutableData new];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWriti开发者_JAVA技巧ngWithMutableData:data];
[archiver encodeObject:myArray forKey:@"array"];
[data writeToFile:filename attomically:YES];
[archiver release];
[data release];
Yes it is possible, quoting Apple documentation :
The NSArray class adopts the NSCopying, NSMutableCopying, and NSCoding protocols;
Note that if you're working with points, maybe you should use the Apple CGPoint
structure, which comes with many handy utilities : CGPointFromString
and NSStringFromCGPoint
see Apple documentation for more information.
And also these others ones might interest you CGPointEqualToPoint
, CGRectContainsPoint
, CGRectIntersectsRect
or CGRectContainsRect
... see Apple documentation for more information
精彩评论