Use stringWithFormat: as a file path in cocoa

Posted by Cam on Stack Overflow See other posts from Stack Overflow or by Cam
Published on 2010-03-13T16:56:07Z Indexed on 2010/03/13 17:05 UTC
Read the original article Hit count: 260

Hello,

I'm having a problem with a cocoa application that takes the value of a text field, and writes it to a file. The file path is made using stringWithFormat: to combine 2 strings. For some reason it will not create the file and the console says nothing. Here is my code:

//Get the values of the text field
NSString *fileName = [fileNameTextField stringValue];
NSString *username = [usernameTextField stringValue];

//Use stringWithFormat: to create the file path
NSString *filePath = [NSString stringWithFormat:@"~/Library/Application Support/Test/%@.txt", fileName];

//Write the username to filePath
[username writeToFile:filePath atomically:YES];

Thanks for any help

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about stringwithformat