I'm running through a RayWenderlich tutorial and I'm a little confused.
Firstly, @autoreleasepool shouldn't be used in iOS5.1 SDK right?
Secondly, Ray goes on to say this
"Take a look at contentsForType first. To create a directory NSFileWrapper, you call initDirectoryWithFileWrapper and pass in a dictionary that contains file NSFileWrappers as the objects, and the names of the files as the key. We use a helper method encodeObject:toWrappers
referredFilename to create a file NSFileWrapper for the data and metadata."
initDIrectoryWithFileWrapper is not coded anywhere, so what is he reffering to here?
Thanks
Source: http://www.raywenderlich.com/12779/icloud-and-uidocument-beyond-the-basics-part-1
Code:
#import "PTKDocument.h"
#import "PTKData.h"
#import "PTKMetadata.h"
#import "UIImageExtras.h"
#define METADATA_FILENAME @"photo.metadata"
#define DATA_FILENAME @"photo.data"
@interface PTKDocument ()
@property (nonatomic, strong) PTKData * data;
@property (nonatomic, strong) NSFileWrapper * fileWrapper;
@end
@implementation PTKDocument
@synthesize data = _data;
@synthesize fileWrapper = _fileWrapper;
@synthesize metadata = _metadata;
- (void)encodeObject:(id<NSCoding>)object toWrappers:(NSMutableDictionary *)wrappers preferredFilename:(NSString *)preferredFilename {
@autoreleasepool {
NSMutableData * data = [NSMutableData data];
NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:object forKey:@"data"];
[archiver finishEncoding];
NSFileWrapper * wrapper = [[NSFileWrapper alloc] initRegularFileWithContents:data];
[wrappers setObject:wrapper forKey:preferredFilename];
}
}
- (id)contentsForType:(NSString *)typeName error:(NSError *__autoreleasing *)outError {
if (self.metadata == nil || self.data == nil) {
return nil;
}
NSMutableDictionary * wrappers = [NSMutableDictionary dictionary];
[self encodeObject:self.metadata toWrappers:wrappers preferredFilename:METADATA_FILENAME];
[self encodeObject:self.data toWrappers:wrappers preferredFilename:DATA_FILENAME];
NSFileWrapper * fileWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:wrappers];
return fileWrapper;
}
Firstly, @autoreleasepool shouldn't be used in iOS5.1 SDK right?
Secondly, Ray goes on to say this
"Take a look at contentsForType first. To create a directory NSFileWrapper, you call initDirectoryWithFileWrapper and pass in a dictionary that contains file NSFileWrappers as the objects, and the names of the files as the key. We use a helper method encodeObject:toWrappers
initDIrectoryWithFileWrapper is not coded anywhere, so what is he reffering to here?
Thanks
Source: http://www.raywenderlich.com/12779/icloud-and-uidocument-beyond-the-basics-part-1