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) NSManagedObjectContext *managedObjectContext;
@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

適当に入れて、一回目のビルド

Undefined symbols for architecture i386:
“_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でエラー

metadata = {
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で保存できたみたいです。

This entry was posted on 水曜日, 6月 20th, 2012 at 4:47 PM and is filed under iOS, Objectiv-C, xcode. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。