Ios 数据未添加到Plist
您好,我在xcode中创建了一个plist(Ios 数据未添加到Plist,ios,xcode,nsarray,plist,nsdictionary,Ios,Xcode,Nsarray,Plist,Nsdictionary,您好,我在xcode中创建了一个plist(newfile->resources->property list,如下所示),我尝试向该plist添加一个NSDictionary,但它没有添加,请帮助我这是我的代码 -(IBAction)Add:(id)sender { _pdfbookmark = [NSMutableArray arrayWithArray:[[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainB
newfile->resources->property list
,如下所示),我尝试向该plist添加一个NSDictionary
,但它没有添加,请帮助我这是我的代码
-(IBAction)Add:(id)sender {
_pdfbookmark = [NSMutableArray arrayWithArray:[[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"pdfBookmarksdata" ofType:@"plist"]] objectForKey:_bookID]];
NSMutableDictionary *bookmark = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"pdfBookmarksdata" ofType:@"plist"]];
if(self.bookmarkIndicator.tintColor == [UIColor blueColor]){
//Already Bookmarked
[_pdfbookmark removeObjectAtIndex:currentBookmarkIndex];
self.bookmarkIndicator.tintColor = [UIColor whiteColor];
}else{
//Create Bookmark
[_pdfbookmark addObject:
@{@"deviceid": @"0",
@"page" : [NSNumber numberWithInt:[self getGlobalPageCount]],
@"fontsize" : [NSNumber numberWithInt:currentTextSize]}];
self.bookmarkIndicator.tintColor = [UIColor blueColor];
}
[bookmark setObject:_pdfbookmark forKey:_bookID];
[bookmark writeToFile:[[NSBundle mainBundle] pathForResource:@"pdfBookmarksdata" ofType:@"plist"] atomically:YES];
}
不允许将文件写入主捆绑包。如果您检查
writeToFile:
方法的返回,您将看到它返回NO
,那么如何写入plist?将它复制到其他地方。有无数的地方将向你展示如何在谷歌上做到这一点。同时阅读此->谢谢@borrden的回答