COREDATA」カテゴリーアーカイブ

CSVFILE READ

平成27年6月24日(水曜日)

COREDATAに重複登録される件について
CSVFILEのファイル末の改行コードに注意!!

Terminating app due to uncaught exception ‘NSObjectInaccessibleException’, reason: ‘CoreData could not fulfill a fault for

coredata更新後に上記エラー発生。他では発生シないため、試しにフェッチリクエストコントローラを入れ替えると発生無し。原因は、cacheName:@”UserSearch”の変更ミス。

新プロジェクトにおけるCOREDATA再考察参考

平成27年3月13日


CSVFILEからのリード(新板)What is the fastest way to load a large CSV file into core data

Objective-CでCSVをプロパティリストに変換する方法

サイトへアップロード
【Objective-C】.plistファイルの作り方と読み込み方
変換ソフトダウンロード
①CSV2Plist
変換ソフトダウンロード 変換不良
②CSV2Plist


平成27年3月5日(木曜日)

Coredata グローバル変数(既存satellite中 appdelegate、modelで使用)〔pageview版〕

既存モデルのCopy バージョニング別プロジェクトからインポート

バンドル セットアップしたデータベースを使う①Core Data Store included in App Bundle

バンドル セットアップしたデータベースを使う②バンドルしておく方法 [最新版]

Creating a CoreData Model in CodeCreating a CoreData Model in Code

サルでもわかる Core Data 入門【概念編

サルでもわかる Core Data 入門【実装編】

CoreDataの一対多関連(One To-Many Relationship)

Core Dataのリレーションシップ勉強

CoreDataのモデルのバージョン移行

CoreData – マイグレーション[1] NSEntityMigrationPolicyを使う

Core Dataの自動マイグレーション

Core Dataの自動マイグレーション②

CoreData – マイグレーション

CoreDataにおいてテーブル定義変更を行う方法

アプリのリリース時からCore Dataにデータをバンドルしておく方法 [最新版]

How to Perform a Lightweight Core Data Migration

coredata

predicate設定

CoreData で複数の条件で絞り込む方法 → AND

検索
右辺値から始まる文字列から右辺値が含まれているかに変更。

CONTAINS(右辺値が含まれているか)

[objc]
//
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"( name CONTAINS %@ )", query];
//[/objc]


BEGINSWITH
右辺値から始まる文字列か

CONTAINS
右辺値が含まれているか

ENDSWITH
右辺値で終わる文字列か

LIKE
右辺値と完全一致するか
ワイルドカードとして「*」「?」が使用可能(*は0文字以上一致、?は1文字以上一致)

MATCHES
正規表現(ICU v3)


COREDATA

平成26年9月6日

マイグレーション調査

[objc]
//
[newManagedObject setValue:[NSNumber numberWithBool:NO] forKey:@"on_off"];
//
[/objc]

平成26年9月5日

model変更(on_off追加)

[objc]
– (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
//modelを変更した場合の対処 その①
/*
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"WeatherForcaster01.sqlite"];
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];

if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
*/

//model変更無し

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"WeatherForcaster01.sqlite"];

if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}

NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

//modelを変更した場合の対処 その② 実使用無し
//—————————-
// Check if we already have a persistent store
if ( [[NSFileManager defaultManager] fileExistsAtPath: [storeURL path]] ) {
NSDictionary *existingPersistentStoreMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType: NSSQLiteStoreType URL: storeURL error: &error];
if ( !existingPersistentStoreMetadata ) {
// Something *really* bad has happened to the persistent store
[NSException raise: NSInternalInconsistencyException format: @"Failed to read metadata for persistent store %@: %@", storeURL, error];
}

if ( ![self.managedObjectModel isConfiguration: nil compatibleWithStoreMetadata: existingPersistentStoreMetadata] ) {
if ( ![[NSFileManager defaultManager] removeItemAtURL: storeURL error: &error] )
NSLog(@"*** Could not delete persistent store, %@", error);
} // else the existing persistent store is compatible with the current model – nice!
} // else no database file yet
//—————————-

if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
/*
Replace this implementation with code to handle the error appropriately.

abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

Typical reasons for an error here include:
* The persistent store is not accessible;
* The schema for the persistent store is incompatible with current managed object model.
Check the error message to determine what the actual problem was.

If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application’s resources directory instead of a writeable directory.

If you encounter schema incompatibility errors during development, you can reduce their frequency by:
* Simply deleting the existing store:
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}

Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}

return _persistentStoreCoordinator;
}
[/objc]