core data | ios
Core Data Programming Guide
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreData/Articles/cdBasics.html#//apple_ref/doc/uid/TP40001650
こんな感じで、保存出来るらしい。sqliteも使えるっぽい。
xcodeでファイル追加
core data ⇒ data modelで
.xcdatamodelというのが出来た。
ここに属性とかを入れていくらしい
チュートリアルしてみる。
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008305
emptyプロジェクトで use core data にチェックすると ヘッダーファイルに
01に書かれているように、Delegate.hに
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
– (NSURL *)applicationDocumentsDirectory;
– (void)saveContext;
が生成されている。
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Articles/02_RootViewController.html
適当に入れて、一回目のビルド
“_OBJC_CLASS_$_CLLocationManager”, referenced from:
objc-class-ref in RootViewController.o
“_kCLLocationAccuracyNearestTenMeters”, referenced from:
-[RootViewController locationManager] in RootViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
こんなエラー。
Build Phases > Link Binary With Libraryes > CoreLocation.framework を追加
とりあえず起動成功。
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Articles/04_Adding.html
build and testでエラー
NSPersistenceFrameworkVersion = 386;
NSStoreModelVersionHashes = {
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
“”
);
NSStoreType = SQLite;
NSStoreUUID = “99D51C0D-ABF5-48E0-BC0E-5B1A1BFAF168″;
“_NSAutoVacuumLevel” = 2;
};
reason = “The model used to open the store is incompatible with the one used to create the store”;
以前開いたモデルは、作った物と違います。とエラーが出て起動出来ない。
* シミュレータ上のlocationsアプリ(データだけでもOK) を一度削除する。
シミュレータから削除すると以下のデータも消える。
/Users/junichi/Library/Application Support/iPhone Simulator/5.1/Applications/アプリID
もう一度起動したらOKでした。
addbuttonを押すとデータが入りました。
deleting event を追加して、edit , delete もOK
とりあえずcore dataで保存できたみたいです。