通常、ユーザーが最初にアプリを起動するときを除いて、データを plist に保存します (JailBroken 電話がハッキングされても気にしないデータのみ、ユーザーの設定など)。次のように plist を作成します。
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pathFirstTime = [documentsDirectory stringByAppendingPathComponent:@"FirstTime.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: pathFirstTime])
{
NSString *bundleFirstTime = [[NSBundle mainBundle] pathForResource:@"FirstTime" ofType:@"plist"];
[fileManager copyItemAtPath:bundleFirstTime toPath:pathFirstTime error:&error];
}
そこで、xcode で空の plist ファイルを作成してバンドルに入れ、ユーザーがアプリを初めて起動したときに、それを documentsDirectory にコピーします...
とにかく、objective-c で初めて空の plist ファイルを作成する方法はありますか?実際に Xcode で作成してバンドルに含める必要はありませんが、ユーザーが最初に起動したときに自動的に作成されます。アプリ...
基本的に、このコードを回避するだけです:[fileManager copyItemAtPath:bundleFirstTime toPath:pathFirstTime error:&error];