ImportableObject
public protocol ImportableObject : DynamicObject
NSManagedObject and CoreStoreObject subclasses that conform to the ImportableObject protocol can be imported from a specified ImportSource. This allows transactions to create and insert instances this way:
class Person: NSManagedObject, ImportableObject {
typealias ImportSource = NSDictionary
// ...
}
dataStack.perform(
asynchronous: { (transaction) -> Void in
let json: NSDictionary = // ...
let person = try transaction.importObject(
Into<Person>(),
source: json
)
// ...
},
completion: { (result) in
// ...
}
)
-
The data type for the import source. This is most commonly an json type,
NSDictionary, or another external source such asNSUserDefaults.Declaration
Swift
associatedtype ImportSource -
shouldInsert(from:Default implementationin: ) Return
trueif an object should be created fromsource. Returnfalseto ignore and skipsource. The default implementation returnstrue.Default Implementation
Declaration
Swift
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> BoolParameters
sourcethe object to import from
transactionthe transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
Return Value
trueif an object should be created fromsource. Returnfalseto ignore. -
Implements the actual importing of data from
source. Implementers should pull values fromsourceand assign them to the receiver’s attributes. Note that throwing from this method will cause subsequent imports that are part of the sameimportObjects(:sourceArray:)call to be cancelled.Declaration
Swift
func didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throwsParameters
sourcethe object to import from
transactionthe transaction that invoked the import. Use the transaction to fetch or create related objects if needed.
View on GitHub
ImportableObject Protocol Reference