pListの作成に使用しているオブジェクトクラスを設定しましたが、いくつか問題があります。クラスでシングルトンデザインパターンを使用しているので、一度に1つのインスタンスを処理するだけで済みます...
奇妙な理由で正常に動作しなくなりました。私の人生では、その理由がわかりません。シングルトンデザインパターンであることに関係があるのかどうか、私は悩んでいます。
#pragma mark Singleton Methods
+ (id)sharedManager {
@synchronized(self) {
if (sharedMyManager == nil)
sharedMyManager = [[self alloc] init];
}
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
// get paths from root direcory (where we will store and fine our plist in the future)
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"EngineProperties.plist"];
NSLog(@"pList path = %@", plistPath);
// check to see if .plist exists in documents
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
{
// if not in documents, get property list from main bundle
plistPath = [[NSBundle mainBundle] pathForResource:@"EngineProperties" ofType:@"plist"];
}
// read property list into memory as an NSData object
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSString *errorDesc = nil;
NSPropertyListFormat format;
// convert static plist into dictionary object (this is where any saved values get put into
savedEnginePropertiesDict = (NSMutableDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
//Load all current values of the property list thats been put into savedEnginePropertiesDict into their variables
if (savedEnginePropertiesDict && [savedEnginePropertiesDict count]){
// assign values
self.sig = [savedEnginePropertiesDict objectForKey:@"Signature"];
self.ver = [savedEnginePropertiesDict objectForKey:@"Version"];
self.num = [savedEnginePropertiesDict objectForKey:@"Number"];
self.dataV = [savedEnginePropertiesDict objectForKey:@"Data"];
self.cache = [savedEnginePropertiesDict objectForKey:@"Cache"];
}
}
return self;
}
これは、plistが存在するディレクトリを作成し、そこにそれを読み取る場合はそれを作成する必要がありますが、それ以外の場合は作成します。しかし、それは何もしません。