2012-02-03 3 views
3

login.txtという名前のファイルにユーザー名であるtextField値を書きたいと思います。WriteToFile:原子的に非難する警告

マイコード:私は ":アトミック:wrtieToFile" として警告を受ける

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

が推奨されていません。

+0

[こちら](https://developer.apple.com/library/IOs/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/DeprecationAppendix/AppendixADeprecatedAPI.html)をご覧ください。 –

答えて

4

それは推奨されませんので、使用:代わりにwriteToFile:atomically

0

The NSString documentation states that it's deprecated

Writes the contents of the receiver to the file specified by a given path. (Deprecated in iOS 2.0. Use writeToFile:atomically:encoding:error: instead.)

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

here見つけることができますwriteToFile:atomically:encoding:error:交換メソッドのドキュメント。

0

iOS 11 writeToFile:atomicallyからは、- writeToUrl:error:が推奨されています。

古い書き込み/読み取りメソッドの多くは、NSArrayのために廃止され、APIは簡略化されているようです。ファイルからNSArrayを作成すると、- initWithContentsOfURL:error:が使用されるようになりました。

関連する問題