Time for action – managing remaining file types
To create an asset manager for our files, use the following steps:
Add a new Objective-C class called
FileManager
, which is derived fromAssetsDictionary
within the Assets group.Define an instance method called
registerPlainText
, as shown in the following code:-(NSString *) registerPlainText:(NSString *)filename;
Define another instance method called
registerDictionaryFromJSON
, as shown in the following code:-(NSDictionary *) registerDictionaryFromJSON:(NSString *)filename;
Implement the
registerPlainText
method with the following content:if ([_dict valueForKey:filename] == nil) { NSString *path = [[NSBundle mainBundle] pathForResource:filename]; NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; return (NSString *) [self registerAsset:filename withContent:content]; } else { return (NSString *) [self registerAsset:filename withContent:nil]; }
Implement the
registerDictionaryFromJSON
...