2011-12-08 19 views
1

私はここに非常に基本的な何かが欠けていると思うが、ここでは行きます。initWithContentsOfFile:エンコーディング:エラー: - NSInvalidArgumentException

Xcodeでインラインヘルプは、initWithContentsOfFileと言われます:がinitWithContentsOfFile 代わり

NSMutableDictionary *myDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; 

を非推奨:エンコーディング:エラー:を使用する必要があります。

NSMutableDictionary *myDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath encoding:NSUTF8StringEncoding error:NULL]; 

私の問題は、そのinitWithContentsOfFileです:以下のコードはエラーを発生させながら、正常に動作し

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"prefs" ofType:@"plist"]; 
Load preferences into symbol dictionary 
NSMutableDictionary *myDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath encoding:NSUTF8StringEncoding error:NULL]; 

ERROR:クリスが私に指摘したように

2011-12-08 16:27:12.209 -[__NSPlaceholderDictionary initWithContentsOfFile:encoding:error:]: unrecognized selector sent to instance 0x4b2a370 
2011-12-08 16:27:12.212 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSPlaceholderDictionary initWithContentsOfFile:encoding:error:]: unrecognized selector sent to instance 0x4b2a370' 
+1

対象とするIOSのバージョンは次のとおりです。限り、バージョン2.0の後に私は[[NSMutableDictionary alloc] initWithContentsOfFile:filePath]をすべて知ることができます。ドキュメントは[こちら](http://developer.apple.com/library/IOs/#documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html#//apple_ref/occ/cl/NSDictionary)です。 initWithContentsOfFile:encoding:NSDictionaryのドキュメンテーションのエラーについては言及していないので、私はそれを明確にします。 –

+0

返事のためのタクク!私はIOS 4.3のために午前中です。 – Kermit

+0

私は今NSDictionaryを使用していますが、XCodeの警告はNSStringのためのものであることに気付きました。奇妙な。クリスおかげで再び! – Kermit

答えて

1

、NSDictionaryのは期待通りに働いています。

XCodeのメソッドをaltキーを押しながらクリックすると、以下のメッセージが表示されます。 奇妙なことに、NSStringとNOT NSDictionaryのドキュメントです。 私の読書ゴーグルを置いておかなければなりません、答えを指摘してくれたChrisにもう一度感謝します!

initWithContentsOfFile: 
Initializes the receiver, a newly allocated NSString object, by reading data from the file named by path. (Deprecated in iOS 2.0. Use initWithContentsOfFile:encoding:error: or initWithContentsOfFile:usedEncoding:error: instead.) 

- (id)initWithContentsOfFile:(NSString *)path 
Discussion 
Initializes the receiver, a newly allocated NSString object, by reading data from the file named by path. If the contents begin with a byte-order mark (U+FEFF or U+FFFE), interprets the contents as Unicode characters; otherwise interprets the contents as data in the default C string encoding. Returns an initialized object, which might be different from the original receiver, or nil if the file can’t be opened. 

Availability 
Available in iOS 4.0 and later. 
Deprecated in iOS 2.0. 
See Also 
– initWithContentsOfFile:encoding:error: 
– initWithContentsOfFile:usedEncoding:error: 
Declared In 
NSString.h 
関連する問題