2012-02-03 107 views
3

我想写一个textField值,它是一个名为login.txt的文件的用户名。WriteToFile:自动弃用警告

我的代码:

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]; 

我得到的警告, “wrtieToFile:原子:” 已被弃用。

+0

Look [here](https://developer.apple.com/library/IOs/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/DeprecationAppendix/AppendixADeprecatedAPI.html) – 2012-02-03 07:03:35

回答

4

因为它已过时,使用:的

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

代替writeToFile:atomically

0

从iOS 11开始已弃用,由- writeToUrl:error:赞成。

好像很多旧的写入/读取方法已被废弃NSArray和api已被简化。因此,从文件创建NSArray现在使用- initWithContentsOfURL:error: