CoreStore icon indicating copy to clipboard operation
CoreStore copied to clipboard

Observe of CoreStoreObject subclass issue

Open Maxim-Inv opened this issue 4 years ago • 3 comments

I try to make observer of the value like described in the documentation:

observer = video.status.observe(options: [.new]) { (video, change) in

but stuck with the error: Generic parameter 'Value' could not be inferred

Screenshot 2020-10-16 at 16 13 41

Here is my model:

class Video: CoreStoreObject {
	@Field.Stored("status")
	var status: String = ""
....
}

And it's ok when I refactor my model to xcdatamodel (to use NSManagedObject subclass):

observer = video.observe(\.status, options: [.new]) { (video, change) in

Maxim-Inv avatar Oct 16 '20 13:10 Maxim-Inv

Maybe the documentation is a little out of date?

I can make it works with CoreStoreObject subclass changing this line to:

observer = video.observe(\Video.$status, options: [.new]) { (video, change) in

Maxim-Inv avatar Oct 16 '20 14:10 Maxim-Inv

Since you are using @Field.Store, the syntax requires $ like you have discovered. The documentation was using examples that used Value.Required and friends, which are not propertyWrappers and thus not need the $ syntax.

JohnEstropia avatar Oct 16 '20 14:10 JohnEstropia

Got it. Thanks. I think it would be better to add this case to the documentation, what do you think?

Maxim-Inv avatar Oct 16 '20 14:10 Maxim-Inv