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 a ListPublisher diffable data source.
I also tried casting O.ObjectID directly to NSManagedObjectID and the same error occurred.
Originally created by @joeljfischer on GitHub (Feb 3, 2020).
It seems to perhaps be an issue with overloading the method?
Doing:
```swift
guard let objectManagedID = self.dataSource.itemID(for: indexPath) else {
return;
}
let timer = CoreStoreDefaults.dataStack.fetchExisting(objectManagedID)
```
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 a `ListPublisher` diffable data source.
I also tried casting `O.ObjectID` directly to `NSManagedObjectID` and the same error occurred.
adam
added the question label 2025-12-29 15:28:36 +01:00
@JohnEstropia commented on GitHub (Feb 4, 2020):
You need to tell it what object type you are querying because it cannot infer it from the ID.
```swift
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
@JohnEstropia commented on GitHub (Feb 4, 2020):
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!
@joeljfischer commented on GitHub (Feb 4, 2020):
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 DiffableDataSources with a shared snapshot.
@JohnEstropia commented on GitHub (Feb 4, 2020):
`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!
@joeljfischer commented on GitHub (Feb 4, 2020):
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 👍
@JohnEstropia commented on GitHub (Feb 5, 2020):
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.
@joeljfischer commented on GitHub (Feb 10, 2020):
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.
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 @joeljfischer on GitHub (Feb 3, 2020).
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.DataSourcemethods after using aListPublisherdiffable data source.I also tried casting
O.ObjectIDdirectly toNSManagedObjectIDand the same error occurred.@JohnEstropia commented on GitHub (Feb 4, 2020):
You need to tell it what object type you are querying because it cannot infer it from the ID.
@JohnEstropia commented on GitHub (Feb 4, 2020):
In the first place, why aren't you getting the object directly from the
ListPublisher?(not the
DiffableDataSource)The
ListPublisher/ListSnapshothas methods/subscripts to get the object directly from theIndexPath@joeljfischer commented on GitHub (Feb 4, 2020):
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 theListPublisher, such aslistPublisher.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 messageValue 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!
@JohnEstropia commented on GitHub (Feb 4, 2020):
listPublisher.snapshot[indexPath]is what you want.It's the other way around actually. The snapshot is your data, and you can actually have multiple
DiffableDataSources with a shared snapshot.@joeljfischer commented on GitHub (Feb 4, 2020):
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
asPublishermethod, so then I could just use that instead. I'll give that a shot, thank you so much for the help!@JohnEstropia commented on GitHub (Feb 5, 2020):
Yes, you'll use
asPublisherto 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 👍
@joeljfischer commented on GitHub (Feb 10, 2020):
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.