My code is simple and pretty much right from the readme but it looks like nothing it being added.
CoreStore.perform(
asynchronous: { (transaction) -> Void in
let person = transaction.create(Into<Person>())
person.name = "John Smith"
person.job = "Dentist" },
completion: { (result) -> Void in
switch result {
case .success: print(result)
case .failure(let error): print(error)
}
let people = CoreStore.fetchAll(From<Person>())
print (people!)
Originally created by @martheli on GitHub (May 25, 2017).
My code runs without error but when I try to print out the entity I receive the following print:
```
success()
[<Person: 0x600000088ac0> (entity: Person; id: 0xd000000000040000 <x-coredata://71CEC961-C7C3-4466-BD1B-DA19FA909453/Person/p1> ; data: <fault>)]
```
My code is simple and pretty much right from the readme but it looks like nothing it being added.
```
CoreStore.perform(
asynchronous: { (transaction) -> Void in
let person = transaction.create(Into<Person>())
person.name = "John Smith"
person.job = "Dentist" },
completion: { (result) -> Void in
switch result {
case .success: print(result)
case .failure(let error): print(error)
}
let people = CoreStore.fetchAll(From<Person>())
print (people!)
```
adam
added the question label 2025-12-29 18:23:29 +01:00
@JohnEstropia commented on GitHub (May 25, 2017):
Did you already add a store using `addStorage()`?
```swift
CoreStore.addStorage(
SQLiteStore(fileName: "MyStore.sqlite"),
completion: { (result) -> Void in
// ...
}
)
```
(See the [Setting-up](https://github.com/JohnEstropia/CoreStore#setting-up) section on the README file)
@martheli Sorry, I just realized you were fetching the object right after calling an asynchronous transaction. perform(asynchronous:...) executes on a background thread, so the object will not be created yet right after the call. You can try fetching inside the completion closure instead:
@JohnEstropia commented on GitHub (May 25, 2017):
@martheli Sorry, I just realized you were fetching the object right after calling an asynchronous transaction. `perform(asynchronous:...)` executes on a background thread, so the object will not be created yet right after the call. You can try fetching inside the `completion` closure instead:
```swift
CoreStore.perform(
asynchronous: { (transaction) -> Void in
let person = transaction.create(Into<Person>())
person.name = "John Smith"
person.job = "Dentist" },
completion: { (result) -> Void in
switch result {
case .success:
let people = CoreStore.fetchAll(From<Person>())
print (people!)
case .failure(let error): print(error)
}
```
That looks like the array contents and the Person objects is in it, so I think there is no problem. You can try to print the person's name and job:
print(people![0].name)print(people![0].job)
@JohnEstropia commented on GitHub (May 26, 2017):
That looks like the array contents and the Person objects is in it, so I think there is no problem. You can try to print the person's name and job:
```swift
print(people![0].name)
print(people![0].job)
```
If people is an array, why can't I just print out the array like "print(people)" to list all the values stored in the entity?
@martheli commented on GitHub (May 26, 2017):
If people is an array, why can't I just print out the array like "print(people)" to list all the values stored in the entity?
Because Core Data has something called faulting.
Basically all fetched objects's values would only be loaded in memory after the first value is accessed. You can see this behavior if you do this:
You'll notice the last print will print the values because name was accessed on the second print
@JohnEstropia commented on GitHub (May 26, 2017):
Because Core Data has something called [faulting](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/FaultingandUniquing.html).
Basically all fetched objects's values would only be loaded in memory after the first value is accessed. You can see this behavior if you do this:
```swift
print(people!)
print(people![0].name)
print(people!)
```
You'll notice the last `print` will print the values because `name` was accessed on the second `print`
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 25, 2017).
My code runs without error but when I try to print out the entity I receive the following print:
My code is simple and pretty much right from the readme but it looks like nothing it being added.
@JohnEstropia commented on GitHub (May 25, 2017):
Did you already add a store using
addStorage()?(See the Setting-up section on the README file)
@martheli commented on GitHub (May 25, 2017):
Yes I have this above:
@JohnEstropia commented on GitHub (May 25, 2017):
@martheli Sorry, I just realized you were fetching the object right after calling an asynchronous transaction.
perform(asynchronous:...)executes on a background thread, so the object will not be created yet right after the call. You can try fetching inside thecompletionclosure instead:@martheli commented on GitHub (May 26, 2017):
I moved it inside the completion and the output is the same; no new values.
@JohnEstropia commented on GitHub (May 26, 2017):
@martheli Can you show your console log?
@martheli commented on GitHub (May 26, 2017):
Output is:
[<Person: 0x600000281680> (entity: Person; id: 0xd000000000040000 <x-coredata://091EEDA4-1652-4D5B-AEA0-110672DEBB1A/Person/p1> ; data: <fault>)]@JohnEstropia commented on GitHub (May 26, 2017):
That looks like the array contents and the Person objects is in it, so I think there is no problem. You can try to print the person's name and job:
@martheli commented on GitHub (May 26, 2017):
If people is an array, why can't I just print out the array like "print(people)" to list all the values stored in the entity?
@JohnEstropia commented on GitHub (May 26, 2017):
Because Core Data has something called faulting.
Basically all fetched objects's values would only be loaded in memory after the first value is accessed. You can see this behavior if you do this:
You'll notice the last
printwill print the values becausenamewas accessed on the secondprint