I am currently writing a simple IOS app that saves tasks into a table. I wanted to expand the app and allow people to share there “lists” with other people. Before saving it to an XML or URL I wanted to try it with a local file using writeToFile:atomically:. This worked great. But I needed the file to be unique to the person using it so I wanted to make the file unique to the title of the the list. Title field is a UITextField. Tasks is a Mutable Array Here is my code:
- (void)saveTask:(id)sender;
{
NSString * original = [titleField text];
NSString * file = [NSString stringWithFormat:@"%@.plist", original];
[tasks writeToFile:@"/tmp/%@.plist",file
atomically:YES];
}
I get an error wanting me to add a “:” into the middle of automatically. How can I use a variable in writeToFile:atomically:? If none of this makes sense please let me know so I can add something. Thank you.
With what you’re doing, you’ll end up with file that has .plist.plist extension.
Beside, the reason why you get an error is, the code should be like this
This might be what you wanted