Originally created by @joeljfischer on GitHub (Feb 3, 2020).
Referencing a property on an ObjectSnapshot<MyObject> where MyObject inherits from CoreStoreObject results in an error:
Referencing subscript 'subscript(dynamicMember:)' on 'ObjectSnapshot' requires that 'MyObject' inherit from 'NSManagedObject'
Do I have to change my object to be an NSManagedObject to get this to work?
Originally created by @joeljfischer on GitHub (Feb 3, 2020).
Referencing a property on an `ObjectSnapshot<MyObject>` where `MyObject` inherits from `CoreStoreObject` results in an error:
> Referencing subscript 'subscript(dynamicMember:)' on 'ObjectSnapshot' requires that 'MyObject' inherit from 'NSManagedObject'
Do I have to change my object to be an `NSManagedObject` to get this to work?
privatefuncprepareObject(_object:MyObject){observer=object.asPublisher(in:CoreStoreDefaults.dataStack)observer?.addObserver(self,{[weakself](publisher)inself?.currentSnapshot=publisher.snapshotifletsnapshot=self?.currentSnapshot{self?.updateUI(snapshot:snapshot)}})}privatefuncupdateUI(snapshot:ObjectSnapshot<MyObject>){ifsnapshot.isPaused{// Accessing a property of MyObject fails with the error noted in the issue descriptionplayPauseButton.setImage(UIImage(systemName:"play.circle.fill"),for:.normal)}else{playPauseButton.setImage(UIImage(systemName:"pause.circle.fill"),for:.normal)}}
@joeljfischer commented on GitHub (Feb 4, 2020):
Sure, I'll try to provide the relevant code:
```swift
private func prepareObject(_ object: MyObject) {
observer = object.asPublisher(in: CoreStoreDefaults.dataStack)
observer?.addObserver(self, { [weak self] (publisher) in
self?.currentSnapshot = publisher.snapshot
if let snapshot = self?.currentSnapshot {
self?.updateUI(snapshot: snapshot)
}
})
}
private func updateUI(snapshot: ObjectSnapshot<MyObject>) {
if snapshot.isPaused { // Accessing a property of MyObject fails with the error noted in the issue description
playPauseButton.setImage(UIImage(systemName: "play.circle.fill"), for: .normal)
} else {
playPauseButton.setImage(UIImage(systemName: "pause.circle.fill"), for: .normal)
}
}
```
@JohnEstropia commented on GitHub (Feb 4, 2020):
What is `isPaused`? Is it a computed property? If so you will need to write that property in an extension:
```swift
extension ObjectSnapshot where O == MyObject {
var isPaused: Bool {
// ...
}
}
```
That's a good catch. It is a computed property, I didn't think about that. So I will need to write the computed property twice, once on an ObjectSnapshot extensions and once on the actual object itself (if I need to access it in both of those contexts)?
@joeljfischer commented on GitHub (Feb 4, 2020):
That's a good catch. It is a computed property, I didn't think about that. So I will need to write the computed property twice, once on an `ObjectSnapshot` extensions and once on the actual object itself (if I need to access it in both of those contexts)?
@JohnEstropia commented on GitHub (Feb 8, 2020):
Unfortunately that's a language limitation for now.
There will be a new way to do this using `@Field.Virtual` in an upcoming version (Swift 5.2): https://github.com/JohnEstropia/CoreStore/issues/359
It will be released soon after Xcode 11.4 goes out of beta.
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).
Referencing a property on an
ObjectSnapshot<MyObject>whereMyObjectinherits fromCoreStoreObjectresults in an error:Do I have to change my object to be an
NSManagedObjectto get this to work?@JohnEstropia commented on GitHub (Feb 4, 2020):
It simply means the signature doesn't match. Can you show the code you are getting this error in?
@joeljfischer commented on GitHub (Feb 4, 2020):
Sure, I'll try to provide the relevant code:
@JohnEstropia commented on GitHub (Feb 4, 2020):
What is
isPaused? Is it a computed property? If so you will need to write that property in an extension:@joeljfischer commented on GitHub (Feb 4, 2020):
That's a good catch. It is a computed property, I didn't think about that. So I will need to write the computed property twice, once on an
ObjectSnapshotextensions and once on the actual object itself (if I need to access it in both of those contexts)?@JohnEstropia commented on GitHub (Feb 8, 2020):
Unfortunately that's a language limitation for now.
There will be a new way to do this using
@Field.Virtualin an upcoming version (Swift 5.2): https://github.com/JohnEstropia/CoreStore/issues/359It will be released soon after Xcode 11.4 goes out of beta.
@joeljfischer commented on GitHub (Feb 10, 2020):
Thanks for the help, this issue can be closed if you wish.