Originally created by @pajtimid on GitHub (Dec 6, 2019).
I'm changing local data and they aren't updating. I have to kill app and after opening again they are updated.
```
dataStack.perform(
asynchronous: { (transaction) -> Void in
let newOffline = transaction.create(Into<CDOffline>())
newOffline.setValues(data: data)
let stored = transaction.fetchOne(
From<CDUserData>()
.where(\.id == Int32(id))
)
if let local= stored {
local.used = newOffline.used
}
},completion: { (result) -> Void in
completion()
})
```
I'm using async callbacks and after completion needs to be updated.
```
func userData(id: Int) -> UserData! {
let storedUserData = self.dataStack.fetchOne(
From<CDUserData >()
.where(\.id == Int32(id))
)
return storedUserData.map{ UserData(fromCoreData: $0) }
}
```
the last func doesnt getting updated local datas.
P.S. In SquelLite browser shows changed data
adam
added the question label 2025-12-29 15:28:20 +01:00
Once any of the monitor/publisher types are attached to that object, you don't need to call anything else to keep that object updated. (Observation will allow you to react to those changes though)
@JohnEstropia commented on GitHub (Dec 7, 2019):
If there aren't any `ListMonitor`s, `ObjectMonitor`s, or `ObjectPublisher`s attached to this object it will never be updated on its own. My suggestion here is to use `ObjectPublisher` as it is the most lightweight. (See https://github.com/JohnEstropia/CoreStore#observe-a-single-objects-updates )
Once any of the monitor/publisher types are attached to that object, you don't need to call anything else to keep that object updated. (Observation will allow you to react to those changes though)
I'm not understanding clearly the way that I should implement this ObjectPublisher. Can you help me on this, where to put publisher?
@pajtimid commented on GitHub (Dec 9, 2019):
I'm not understanding clearly the way that I should implement this ObjectPublisher. Can you help me on this, where to put publisher?
Please make sure that the "dataStack" is the SAME one, otherwise your update would not works in different dataStack, unless you relaunch the app
@AlwaysBee commented on GitHub (Dec 15, 2019):
Please make sure that the "dataStack" is the SAME one, otherwise your update would not works in different dataStack, unless you relaunch the app
I'm not understanding clearly the way that I should implement this ObjectPublisher. Can you help me on this, where to put publisher?
@pajtimid As @AlwaysBee mentioned, it's possible you are using a default-initialized stack. This is a much more common mistake so please check first that:
The DataStack you created and assigned to self.dataStack is not getting accessed anywhere else before your addStorage(...) executes its completion block.
The DataStack you are calling perform(asynchronous:completion:) on is still the same instance as (1)
The DataStack you are calling fetchOne(_:) on is still the same instance as (1) and (2)
@JohnEstropia commented on GitHub (Dec 16, 2019):
> I'm not understanding clearly the way that I should implement this ObjectPublisher. Can you help me on this, where to put publisher?
@pajtimid As @AlwaysBee mentioned, it's possible you are using a default-initialized stack. This is a much more common mistake so please check first that:
1. The `DataStack` you created and assigned to `self.dataStack` is not getting accessed anywhere else before your `addStorage(...)` executes its `completion` block.
2. The `DataStack` you are calling `perform(asynchronous:completion:)` on is still the same instance as (1)
3. The `DataStack` you are calling `fetchOne(_:)` on is still the same instance as (1) and (2)
I solved it. My problem was on: one-to-many relationship.
My locations variable is Set<Locations> type
` for location in locations {
let newDataLocations = transaction.create(Into<CDDataLocations>())
newDataLocations.setValues(dataLocations: location)
newData.locations.insert(newDataLocation)
}`
I removed this line newData.locations.insert(newDataLocation)
and updated well.
I don't know why this is happening!
@pajtimid commented on GitHub (Dec 20, 2019):
I solved it. My problem was on: one-to-many relationship.
My` locations` variable is `Set<Locations> `type
```
` for location in locations {
let newDataLocations = transaction.create(Into<CDDataLocations>())
newDataLocations.setValues(dataLocations: location)
newData.locations.insert(newDataLocation)
}`
```
I removed this line
`newData.locations.insert(newDataLocation)`
and updated well.
I don't know why this is happening!
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 @pajtimid on GitHub (Dec 6, 2019).
I'm changing local data and they aren't updating. I have to kill app and after opening again they are updated.
I'm using async callbacks and after completion needs to be updated.
the last func doesnt getting updated local datas.
P.S. In SquelLite browser shows changed data
@JohnEstropia commented on GitHub (Dec 7, 2019):
If there aren't any
ListMonitors,ObjectMonitors, orObjectPublishers attached to this object it will never be updated on its own. My suggestion here is to useObjectPublisheras it is the most lightweight. (See https://github.com/JohnEstropia/CoreStore#observe-a-single-objects-updates )Once any of the monitor/publisher types are attached to that object, you don't need to call anything else to keep that object updated. (Observation will allow you to react to those changes though)
@pajtimid commented on GitHub (Dec 9, 2019):
I'm not understanding clearly the way that I should implement this ObjectPublisher. Can you help me on this, where to put publisher?
@AlwaysBee commented on GitHub (Dec 15, 2019):
Please make sure that the "dataStack" is the SAME one, otherwise your update would not works in different dataStack, unless you relaunch the app
@JohnEstropia commented on GitHub (Dec 16, 2019):
Ah yes, there is this too
@JohnEstropia commented on GitHub (Dec 16, 2019):
@pajtimid As @AlwaysBee mentioned, it's possible you are using a default-initialized stack. This is a much more common mistake so please check first that:
DataStackyou created and assigned toself.dataStackis not getting accessed anywhere else before youraddStorage(...)executes itscompletionblock.DataStackyou are callingperform(asynchronous:completion:)on is still the same instance as (1)DataStackyou are callingfetchOne(_:)on is still the same instance as (1) and (2)@pajtimid commented on GitHub (Dec 20, 2019):
I solved it. My problem was on: one-to-many relationship.
My
locationsvariable isSet<Locations>typeI removed this line
newData.locations.insert(newDataLocation)and updated well.
I don't know why this is happening!