NSUserDefaults
is not what you're looking for. Technically it would work for what you want, but you're probably better off just making a custom class that has a property for all of the recipe characteristics and making the class conform to the <NSCoding>
protocol so that you can convert it to data and write it to a file.
I know that might sound complicated if you've never done it before but it's really not too bad.
Here's an example for implementing <NSCoding>
. Ignore the end part where it shows you saving the data to NSUserDefaults
.
To save your data, instead of using NSUserDefaults, take a look at this question. It might seem like a lot of code for a small task, but the concept is pretty simple.
Edit:
To convert your object to data, assuming you've already implemented <NSCoding>
in your custom class:
YourClass* someObject;
// do whatever you do to fill the object with data
NSData* data = [NSKeyedArchiver archivedDataWithRootObject:someObject];
/*
Now we create the path to the documents directory for your app
*/
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
/*
Here we append a unique filename for this object, in this case, 'Some_Recipe'
*/
NSString* filePath = [documentsDirectory stringByAppendingString:@"Some_Recipe"];
/*
Finally, let's write the data to our file
*/
[data writeToFile:filePath atomically:YES];
/*
We're done!
*/