Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
I was data to persist when a user is filling out a form. However, I want that data erased from temporary storage when the form is completed.

Would it be a good idea to use NSUserDefaults when the user is filling out the form (in the event the App terminates/pauses), and NSCoding when the form is submitted and the data is sent to local storage?

Any advice would be great.
 
I'm using NSUserDefaults for my data entry forms of my app "Gas By Numbers".
The distance driven, the gasamount refilled and the gasprice is being entered on 2 different UIViews. On the 3rd View, the data gets calculated and displayed. If the user decides to save the data, it's being written to a local file which is not visible via iTunes sharing. If the user decides to make the data available for use on a PC or Mac, all the data is being written to a new file in the documents folder on the iDevice and it's shared via iTunes.

Hope this helps, Mike.
 
Thanks Mike.

I didn't realise that storing data in the documents folder meant that it appeared in iTunes sharing.

When creating a plist file I look for the doc directory like so.

Code:
-(NSString*)documentDirectory
{
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [path objectAtIndex:0];
}

-(NSString*)path
{
    return [[self documentDirectory] stringByAppendingPathComponent:@"Options.plist"];
}

I then call 'path'.

How do you store data in a different directory to the one I have mentioned here. For instance, something other than the documents folder.
 
It won't show up in iTunes file sharing unless you have iTunes file sharing set to yes. Also, files that you don't want to be backupped to iCloud you should set to "not backupped", otherwise your app will also get rejected (happened to me).
for 1 app, we write everything to plist, with NSCoding, instead of NSUserDefaults, also Base64 encrypted, because you can drag plists from the device with iExplorer, even if it's not non-jailbroken phone. so better to be a bit safe with your users stuff ^_-
 
It won't show up in iTunes file sharing unless you have iTunes file sharing set to yes. Also, files that you don't want to be backupped to iCloud you should set to "not backupped", otherwise your app will also get rejected (happened to me).
for 1 app, we write everything to plist, with NSCoding, instead of NSUserDefaults, also Base64 encrypted, because you can drag plists from the device with iExplorer, even if it's not non-jailbroken phone. so better to be a bit safe with your users stuff ^_-

thanks
By conforming to NSCoding protocols, are you automatically encrypting with Base64? If no, then how to you go about encrypting a plist with that?
 
Nope, Base64 is not standard in iOS, it is for Mac OSX though..
You basically need to find a library online for Base64, include it in your project.
Mostly it's just a category on NSString which makes you do [stringPointer encryptBase64]; which then encrypts it, and then you can store that to your plist :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.