1
我想我缺少的東西非常基本的在這裏,但它在這裏。initWithContentsOfFile:編碼:錯誤: - NSInvalidArgumentException
在Xcode中內嵌幫助告訴我,initWithContentsOfFile:棄用
NSMutableDictionary *myDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
相反initWithContentsOfFile:編碼:錯誤:應該被使用。
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];
錯誤:
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'
您定位的IOS版本是什麼。據我可以告訴版本2.0後的一切[[NSMutableDictionary alloc] initWithContentsOfFile:filePath]。文檔是[here](http://developer.apple.com/library/IOs/#documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html#//apple_ref/occ/cl/NSDictionary)。我在NSDictionary的文檔中看不到initWithContentsOfFile:encoding:error,所以我會避免這樣做。 –
Thaks的答覆!我對iOS 4.3非常感興趣。 – Kermit
我注意到了,XCode警告是針對NSString的,儘管我使用的是NSDictionary。奇怪。再次感謝克里斯! – Kermit