I want write a textField value which is a user name to file named login.txt.
My code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// the path to write file
loginFilePath= [documentsDirectory stringByAppendingPathComponent:@"Login.txt"];
NSString *userName=[nameText text];
[userName writeToFile:loginFilePath atomically:YES];
I get Warning as "wrtieToFile:atomically:" is deprecated.
Because it is deprecated, use:
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error;
instead of writeToFile:atomically
As of iOS 11 writeToFile:atomically has been deprecated in favour of - writeToUrl:error:.
It seems like a lot of the old write/read methods have been deprecated for NSArray and the api has been simplified. So creating an NSArray from a file now uses - initWithContentsOfURL:error:.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With