Originally created by @martheli on GitHub (May 27, 2017).
I have an array like this:
let array = ["John", "Maria", "Erika", "Susan"]
And I would like this array to be imported into my Persons entity. I have read the README in regards to importing arrays and I am not sure if just using the below is sufficient?
CoreStore.perform(
asynchronous: { (transaction) -> Void in
try! transaction.importObject(
Into<Person>(),
source: Array
)
},
completion: { _ in }
)
I am getting "Ambiguous reference to member importObject" error. Am I supposed to add the following class to my project before the import works?
public protocol ImportableObject: class {
typealias ImportSource
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool
func didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throws
}
Originally created by @martheli on GitHub (May 27, 2017).
I have an array like this:
`let array = ["John", "Maria", "Erika", "Susan"]`
And I would like this array to be imported into my Persons entity. I have read the README in regards to importing arrays and I am not sure if just using the below is sufficient?
```
CoreStore.perform(
asynchronous: { (transaction) -> Void in
try! transaction.importObject(
Into<Person>(),
source: Array
)
},
completion: { _ in }
)
```
I am getting "Ambiguous reference to member importObject" error. Am I supposed to add the following class to my project before the import works?
```
public protocol ImportableObject: class {
typealias ImportSource
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool
func didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throws
}
```
adam
added the question label 2025-12-29 18:23:29 +01:00
Yes, you will need to implement ImportableObject or ImportableUniqueObject methods first.
You can only import from the type you declare ImportSource as. For example, if you set
@JohnEstropia commented on GitHub (May 28, 2017):
Yes, you will need to implement `ImportableObject` or `ImportableUniqueObject` methods first.
You can only import from the type you declare `ImportSource` as. For example, if you set
```swift
typealias ImportSource = [String: Any]
func didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throws {
self.name = source["name"] as! String?
}
```
you can import a single object with
```swift
try transaction.importObject(
Into<Person>(),
source: ["name": "John"]
)
```
and multiple objects with
```swift
try transaction.importObjects(
Into<Person>(),
sourceArray: [
["name": "John"],
["name": "Maria"],
["name": "Erika"],
["name": "Susan"]
]
)
```
Whenever I use the following, I get error that says "Typealias is missing an assigned type":
typealias ImportSource = [String: Any]
public protocol ImportableObject: class {
typealias ImportSource
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool
func didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throws
}
@martheli commented on GitHub (May 28, 2017):
Whenever I use the following, I get error that says "Typealias is missing an assigned type":
```
typealias ImportSource = [String: Any]
public protocol ImportableObject: class {
typealias ImportSource
static func shouldInsert(from source: ImportSource, in transaction: BaseDataTransaction) -> Bool
func didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throws
}
```
I would suggest you familiarize yourself first with Swift and Core Data in general as CoreStore's documentation assumes you have sufficient background on both.
@JohnEstropia commented on GitHub (May 28, 2017):
The typealias needs to be implemented in your class. Please read the [Swift documentation on `associatedtype`](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Generics.html#//apple_ref/doc/uid/TP40014097-CH26-ID189).
I would suggest you familiarize yourself first with Swift and Core Data in general as CoreStore's documentation assumes you have sufficient background on both.
@JohnEstropia commented on GitHub (May 29, 2017):
Sorry, there's no demo code for importing yet. But the Unit tests do have a sample code you can refer to: https://github.com/JohnEstropia/CoreStore/blob/develop/CoreStoreTests/ImportTests.swift#L1068
By the way, for general questions/discussions you may want to join the CoreStore Slack group:
http://swift-corestore-slack.herokuapp.com/
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @martheli on GitHub (May 27, 2017).
I have an array like this:
let array = ["John", "Maria", "Erika", "Susan"]And I would like this array to be imported into my Persons entity. I have read the README in regards to importing arrays and I am not sure if just using the below is sufficient?
I am getting "Ambiguous reference to member importObject" error. Am I supposed to add the following class to my project before the import works?
@JohnEstropia commented on GitHub (May 28, 2017):
Yes, you will need to implement
ImportableObjectorImportableUniqueObjectmethods first.You can only import from the type you declare
ImportSourceas. For example, if you setyou can import a single object with
and multiple objects with
@martheli commented on GitHub (May 28, 2017):
Whenever I use the following, I get error that says "Typealias is missing an assigned type":
@JohnEstropia commented on GitHub (May 28, 2017):
The typealias needs to be implemented in your class. Please read the Swift documentation on
associatedtype.I would suggest you familiarize yourself first with Swift and Core Data in general as CoreStore's documentation assumes you have sufficient background on both.
@martheli commented on GitHub (May 29, 2017):
Do any of the demos that you attached, include a sample of how to import data from JSON?
@JohnEstropia commented on GitHub (May 29, 2017):
Sorry, there's no demo code for importing yet. But the Unit tests do have a sample code you can refer to: https://github.com/JohnEstropia/CoreStore/blob/develop/CoreStoreTests/ImportTests.swift#L1068
By the way, for general questions/discussions you may want to join the CoreStore Slack group:
http://swift-corestore-slack.herokuapp.com/