0
我怎樣才能被搜索到NSUserDomainMask的setObject到myPlist?我需要點擊一個保存按鈕來保存文本在本地存儲在我的應用程序沙盒中的plist上。感謝是否有示例代碼或教程,謝謝。
我怎樣才能被搜索到NSUserDomainMask的setObject到myPlist?我需要點擊一個保存按鈕來保存文本在本地存儲在我的應用程序沙盒中的plist上。感謝是否有示例代碼或教程,謝謝。
//文件(NSArray的NSDictionary的或)被保存在data.plist文件
- (IBAction爲)saveFile的:(ID)發送{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectoryPath
stringByAppendingPathComponent:@"data.plist"];
[file writeToFile:filePath atomically: YES];
}
這個代碼的任何想法? (NSString *)dataFilePath { NSArray * path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString * documentsDirectoryPath = [path objectAtIndex:0]; NSArray * filePath = [documentsDirectoryPath stringByAppendingPathComponent:@「myList.plist」]; dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath]; 返回字典; } ' – Albert
NSNumber * number = [NSNumber numberWithInt:3]; [dictionary setObject:number forKey:@「key3」];對於(id鍵在字典中){ ({「key key in dictionary」){NSLog(@「web key =%@,value =%@」,key,[dictionary objectForKey:key]); [dictionary writeToFile:[self dataFilePath] atomically:YES]; – Albert
@ user1049312我的代碼將搜索文檔目錄的路徑,然後將文件名添加到文檔目錄路徑中...將給出文件的路徑...然後在該路徑上寫入文件。 –