Database Reference
In-Depth Information
- (id)init {
return [self initWithFirstName:nil lastName:nil displayName:nil favoriteNumber:nil
andPhoto:nil];
}
#pragma mark - NSCoding Methods
- (id)initWithCoder:(NSCoder *)aDecoder {
NSInteger version = [aDecoder decodeIntForKey:kVersionKey];
if(version == 1){
NSString *firstName = [aDecoder decodeObjectForKey:kFirstNameKey];
NSString *lastName = [aDecoder decodeObjectForKey:kLastNameKey];
NSString *displayName = [aDecoder decodeObjectForKey:kDisplayNameKey];
NSNumber *favoriteNumber = [aDecoder decodeObjectForKey:kFavoriteNumberKey];
NSData *photoData = [aDecoder decodeObjectForKey:kPhotoKey];
UIImage *photo = [UIImage imageWithData:photoData];
return [self initWithFirstName:firstName lastName:lastName displayName:displayName
favoriteNumber:favoriteNumber andPhoto:photo];
} else {
return [self init];
}
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeInt:1 forKey:kVersionKey];
[aCoder encodeObject:_firstName forKey:kFirstNameKey];
[aCoder encodeObject:_lastName forKey:kLastNameKey];
[aCoder encodeObject:_displayName forKey:kDisplayNameKey];
[aCoder encodeObject:_favoriteNumber forKey:kFavoriteNumberKey];
NSData *photoData = UIImagePNGRepresentation(_photo);
[aCoder encodeObject:photoData forKey:kPhotoKey];
}
@end
Now that we have the data model out of the way we can bring it all into a UIDocument subclass.
CTDocument
Create a new Objective-C class that is a subclass of UIDocument and call it CTDocument . In the
preceding CTDocument.h file the @interface line we need to add a class declaration for CTData and
CTMetadata .
@class CTData;
@class CTMetadata;
 
Search WWH ::




Custom Search