iphone - 如何在 iOS 编程中使用 pList

标签 iphone objective-c ios cocoa-touch

最近,我是一名高中生,我对为 iPhone 制作应用很感兴趣。最近,我的一个应用程序问世了:NBlock。这是一个益智应用程序,非常具有挑战性。但是,它有一些问题。高分不保存。有人告诉我要使用 plist。有什么建议吗?

最佳答案

基于 URL 的方法:

// Get the URL for the document directory
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSURL *documentDirectoryURL = [[fileManager URLsForDocumentDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] objectAtIndex:0];

// Turn the filename into a string safe for use in a URL
NSString *safeString = [@"scores.plist" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

// Create an array for the score
NSMutableArray *array = [[NSMutableArray alloc] init];      
[array addObject:[NSNumber numberWithInt:score]];

// Write this array to a URL
NSURL *arrayURL = [NSURL URLWithString:safeString relativeToURL:documentDirectoryURL];
[array writeToURL:arrayURL atomically:YES];

关于iphone - 如何在 iOS 编程中使用 pList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7059966/

相关文章:

ios - 使用 ccrypto RSA 加密 2500 字节数据

iOS 为什么在设置 NSBaselineOffsetAttributeName 时 NSTextAttachment 会消失?

android - Opa 可以用于手机和平板电脑开发吗?

ios - 如何处理 Objective-C 模型关系中的循环引用

ios - 使用相同的本地化按钮切换语言应用程序

ios - 共享扩展不显示数据 -- ios

ios - 某些 iOS 框架如何使用不带 @objc 的可选来定义 Swift 协议(protocol)?

ios - 如何在 iPhone 应用程序中设置特定键盘?

ios - 是否有可能创建对结构数组元素的引用?

iphone - iPhone 上链接器标志 force_load 的 xcode project-/target-settings-syntax