Q:

How to use NSUserDefaults to allocate space dynamically?

I ve used NSUserDefaults before , to store some variables for the settings section of my application.
However now i am making a recipes application , where the user can type in his own recipes and saves them. Each recipe has a title a description a date etc.. So i guess i ll need an array to save every recipe. But how will i add every new recipe dynamically? 
I mean i ll just start to save the recipe in the next position on the array? and what happens if the user deletes one recipe and theres a free position in the array?
My logic here is correct on saving the data? What would you do?

A:

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!
 */

