I am creating an add-on on my app where users search for something already populated in a list Could one. With the data from the plist file it is an NSDictionary if the word has been searched by the user does not exist, then the user can tap a + button and add it, so next time it is.
At first I thought it would be as easy to use as NSUserDefaults, but some problems arise.
To join the list, I should put him in the bundle, but if he is there then I can not add new key / value to it. I can do this only with files located in the Documents folder.
So I think I have to bundle Plist, then on the first run I will take her to the folder of documents and she will be there.
This problem opens when I have to update the app, I think it will overwrite that user's values.
Edit a safe, easy-to-understand,
Edit: * ** *
/ Strong> The real view, as * ** * * as suggested by The Squad and Tom < / P> + (NSMutableDictionary *) generic products {nsfil manager * file manager = [nsfile manager default manager]; NSArray * documentPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, yes); NSString * Document Directory = [documentPaths ObjectTime: 0]; NSString * documentPlistPath = [document directory stringingbapping money company: @ "generic products. Plast"]; NSSTING * Bundle Path = [[NSBindal Main Bundle] Bundle Path]; NSString * bundlePlistPath = [Bundle Path Stringbapping Padding Contract: @ "Generic Products. Plast"]; If ([file manager filesxxtapath: documentpelistpath]) {nsmutibilaxide document document = [NSMutableDictionary dictate with contentofffile: documentPlistPath]; Return document; } And {NSError * error; BOOL success = [fileManager copyItemAtPath: bundlePlistPath toPath: documentPlistPath error: & amp; Error]; If (success) {NSMutableDictionary * Navisites Dict = [NSMutableDictionary DictionaryWithContentsOfFile: documentPlistPath]; Fresh dick back; } Return zero; }
}
and to add a new product to the list:
+ (zero) addItemToGenericProducts: (NSString *) NewProduct {NSArray * documentPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, Yes); NSString * Document Directory = [documentPaths ObjectTime: 0]; NSString * documentPlistPath = [document directory stringingbapping money company: @ "generic products. Plast"]; NSMutableDictionary * documentDict = [NSMutableDictionary DictionaryVersion contentoff file: documentPlistPath]; [DocumentDict Set Object: newProduct forKey: [MD5Checksum cheksum: newProduct]]; [DocumentDict writeToFile: documentPlistPath Atomic: Yes];
}
My views with my Siklit database were the same ...
I'm actually doing this, be able to modify the bundle file to be copied in the document.
What I have done is checking every startup file that exists, if it is not, then copy it. If you update your app, the document folder will not touch, this means that the copied file from the previous version will still be present.
The only issue is that if you want to upgrade your plan, you have to handle it in your application. If you have to do this, then I recommend that you use NSUserDefault to check that the previous version of the app already exists ...
Comments
Post a Comment