Reputation: 10245
I have set up a object class that I am using to create my pList however I am having some issues with it. I am using the singleton design pattern on the class so I only have to deal with one instance of it at any one time...
for some weird reason it has stopped working properly and for the life of me I cannot figure out why, I am woundering if it has something to do with it being in a singleton design pattern..
#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;
}
This should be creating the directory where the plist should reside, then if its there reading it, else creating it.. but its not doing any of that.. and I am at a complete loss as to figuring out why its not working.
Upvotes: 0
Views: 177
Reputation: 50727
Your setting the values, but not writing to file.
[savedEnginePropertiesDict writeToFile: plistPath atomically: YES];
Upvotes: 1