mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
What is DynamicObject Protocol and how do I conform to it? #363
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AryasDad on GitHub (May 23, 2021).
I have been using Core Store for a few years on several small personal app projects.
I am now trying to create a complex app and am starting to delve into SwiftUI. I was using the Modern.ColorsDemo.SwiftUI as a guide for implementing a SwiftUI list using ListSnapshot and ListPublisher. However, whenever I mimic and add the following in my view file:
@ListState private var locations: ListSnapshot
I get the following error in Xcode: "Type 'Settings.Locations' does not conform to protocol 'DynamicObject'"
Settings.Location is my SwiftUI List View file. I do not see anything special in the Demo that I do not have in my files, other than your demo is using the built-in Core Store data models. I am not ready to jump off into using this for my models, since I still like using the "graphic" helpers with the built-in xcdatamodel for complex relationships.
So I poked around some more and saw dynamic keywords on xcdatamodel classes in the Advanced.EvolutionDemo.V2.Creature class files. I have been using Codegen. So I then decided to experiment and generate my on model class and change the definition of the entities to dynamic instead of public.
That did nothing to help. Google gives me absolutely NO results on what a DynamicObject protocol is after trying several different ways to ask. I can't even find DynamicObject in Apple Documentation or anywhere on Apple Developer forums.
I am hoping I am missing something obvious, but I cannot figure it out. Can you help point me in the direction to figure out what my issue is?
@AryasDad commented on GitHub (May 23, 2021):
Though I still have no idea what DynamicObject protocol is, I was able to get it fixed. I had to go one more step up the ladder to Modern.ColorsDemo.MainView to see what is being placed in these items. To fix my view, I had to do the following:
Change @ListState
from: @ListState private var locations: ListSnapshot
to: @ListState(coreDataHelper.publisherLocations) private var locations: ListSnapshot
Change init
from: self._locations = .init(ListPublisher)
to: self._locations = .init(self.$locations)
Those items seemed to do the trick. Though not sure why it throws the error, since the way I had it setup previous was similar to the demo where it could be reused and the initiated when inserted into another view. I realize I do not need that flexibility, so stuck the actually data in the file instead of having it be dynamic placeholders like the demo.
Thanks!
@JohnEstropia commented on GitHub (May 24, 2021):
@AryasDad Glad you had it fixed, but just to explain what was going on, you were missing a generic type on
ListSnapshot. Your declaration would resolve the first issue (or at least give a clearer error message) if it was declared as: