Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WriteToFile:atomically deprecate Warning

Tags:

ios

iphone

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.

like image 987
anjum Avatar asked Dec 16 '25 15:12

anjum


2 Answers

Because it is deprecated, use:

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error;

instead of writeToFile:atomically

like image 86
Tomasz Wojtkowiak Avatar answered Dec 19 '25 05:12

Tomasz Wojtkowiak


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:.

like image 38
smileBot Avatar answered Dec 19 '25 06:12

smileBot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!