【发布时间】:2011-06-25 03:22:23
【问题描述】:
我是一位经验丰富的 iOS 开发人员,正在尝试制作我的第一个 Mac 应用程序。我想使用核心数据将数据存储在我的应用程序中。在我的 iOS 应用程序中,我通常有一个预先创建的 SQLite 文件,它用作数据存储的初始状态,并在应用程序第一次运行时移动到位,如下所示:
NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Datafile.sqlite"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"Datafile-DefaultData" ofType:@"sqlite"];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}
我想在mac应用程序中做类似的事情,除了将数据放在~/Library/Application Support/MyApp目录中。我似乎无法弄清楚该怎么做。有什么指点吗?
【问题讨论】:
标签: cocoa macos core-data nsfilemanager