Closed joeljfischer closed 4 years ago
You need to tell it what object type you are querying because it cannot infer it from the ID.
let timer: TimerObject = CoreStoreDefaults.dataStack.fetchExisting(objectManagedID)
In the first place, why aren't you getting the object directly from the ListPublisher
?
(not the DiffableDataSource
)
The ListPublisher
/ListSnapshot
has methods/subscripts to get the object directly from the IndexPath
That was the first place I looked, but I don't see a publicly available method for getting the object from the IndexPath
. I checked the current snapshot of the ListPublisher
, such as listPublisher.snapshot.items(atIndices:)
, but that's designed for the diffible data source and I'd have to figure out how to do a bunch of conversion.
Attempting to directly subscript it like so let item = listPublisher?[indexPath]
leads to this error message Value of type 'ListPublisher<MyObject>' has no subscripts
.
If you could point me in the right direction, that would be appreciated!
EDIT: Your first comment did work, however, so I can continue to use that. If there's a better / easier way though, I'd love to use that!
listPublisher.snapshot[indexPath]
is what you want.
... but that's designed for the diffible data source and I'd have to figure out how to do a bunch of conversion.
It's the other way around actually. The snapshot is your data, and you can actually have multiple DiffableDataSource
s with a shared snapshot.
I see what you're saying. The issue I'm trying to solve is passing the object into a table view cell, which can then observe the object. It looks like the snapshot has an asPublisher
method, so then I could just use that instead. I'll give that a shot, thank you so much for the help!
Yes, you'll use asPublisher
to convert the snapshot to a "live" object. In general, any form of "read" (from indexPaths, or from property values) is done through an intermittent "state" (ListSnapshot, ObjectSnapshot) because the publisher variants may change anytime.
Although, I think if you had trouble finding the current accessors then the documentation might be lacking somewhere, or the current methods are not intuitive enough. I'll see how we can improve the utilities 👍
Thanks for the support again. I agree that was not entirely clear in the documentation, but it makes more sense now. This issue can be closed if you wish.
It seems to perhaps be an issue with overloading the method?
Doing:
causes an error:
Argument type 'O.ObjectID' (aka 'NSManagedObjectID') does not conform to expected type 'DynamicObject'
I'm doing this to pull my object in my
UITableView.DataSource
methods after using aListPublisher
diffable data source.I also tried casting
O.ObjectID
directly toNSManagedObjectID
and the same error occurred.