use NSFetchRequest
to
Core data handles multi-writing conflicts ,migration and persistent store vs. in-memory
var haspersistentChangedValues: Bool { get }
in NSManagedObject
marks the object are dirty and prevent false positive
func objectIDsForRelationshipNamed(key: String) -> [NSManagedObjectID]
for fetching 1 to many objects
refreshAllObjects()
for
class func mergeChangesFromRemoteContextSave(changeNotificationData:[NSObject : AnyObject], intoContexts contexts: [NSManagedObjectContext])
var shouldDeleteInaccessibleFaults: Bool
We often need to remove the underlying database and create a new one for latest data. By doing so, that leaves many issues such as corrupting the files and bad access to the live connections
func destroyPersistentStoreAtURL(url: NSURL, withType storeType: String,options: [NSObject : AnyObject]?) throws
At the same we may need to replace one db with other
func replacePersistentStoreAtURL(destinationURL: NSURL, destinationOptions:[NSObject : AnyObject]?, withPersistentStoreFromURL sourceURL: NSURL, sourceOptions: [NSObject : AnyObject]?, storeType: String) throws
In Xcode 7, we can define what property of a model can be used as unique identifier.
For current situation, if we need to delete some objects, we have to do the following 4 steps
NSBatchDeleteRequest
is new api for us to not to pre-fetching the objects with focus on deleting
returns
and limitations are:
we often update the models as app versions advance. Migration is needed to perform for differnt versions
Problem
in iOS 9
Model caching as last-ditch effort to recover
limitation
__kindof
no need to update the header for adding new properties. Instead, editing Subclass+NSMAngedProperties.h
or Subclass+NSMangedProperties.swift
for adding those new properties.
init(concurrencyType:)
is the designated initializer
Related session: What's new in Core Data on iOS WWDC 2011 or NSManagedObjectContext Documentation
Use instrutment to measure the performance and find the data that should not prefetch
use -com.apple.CoreData.SQLDebug 1
for show query SQL and running time
then use EXPLAIN QUERY PLAN [sql]
to see the steps of the execution of sql