它剛剛發生在我身上我不知道如何最好地處理像這樣的情況是我從磁盤檢索一個對象,在這種情況下,我知道它只應該是NSDictionary
。但是,做出假設的做法並不是很好的編碼實踐......是檢查它是哪個類的常態,然後將其轉換爲Dictionary?Obj-C持久性和動態類型檢測
如果是這樣,我會首先檢索NSData
類中的文件,然後詢問它是否是NSDictionary
類?
NSString *destinationString = [NSString stringWithFormat:@"%@/%@",dataPath,filename];
NSDictionary *file = [[NSDictionary alloc]initWithContentsOfFile:destinationString];
if (file) {
return YES;
}
return NO;
}
你看過[NSUserDefaults](http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSUserDefaults_Class/Reference/Reference.html)嗎? –
@Marcus:我將使用NSUserDefaults來做一些非常簡單的條件檢查。但爲此,我需要更好的東西。 –