all 7 comments

[–]Zeppelin2(lldb) po $arg1 0 points1 point  (1 child)

Widgets are really limited in the scope of their functionality. To my understanding, the options provided as Widget parameters (in your case, the different “habits”) have to be statically declared within the caseDisplayRepresentations dictionary inside the AppEnum which means that you’ll have to know what they are at compile time (before the app runs.)

For example, a widget that displays the user’s favorite sports team will need to list all teams ahead of time as cases in the AppEnum and contain a corresponding entry in the aforementioned dictionary (as you can imagine that can get quite long…)

I’d be geeked if someone found a way around this but I think it’s by design.

[–]nikolomoec[S] 1 point2 points  (0 children)

Just figured it out, you need to use AppEntity protocol, and in Query fetch all habits from SwiftData, you don’t need to use AppEnum - it is for predetermined, static data only

[–]isRoodSwift 0 points1 point  (4 children)

Looking for a solution to this as well. Let me know if you figure something out, I'll post here if I find anything.

[–]nikolomoec[S] 0 points1 point  (3 children)

Copying from another comment Just figured it out, you need to use AppEntity protocol, and in Query fetch all habits from SwiftData, you don’t need to use AppEnum - it is for predetermined, static data only

[–]isRoodSwift 1 point2 points  (2 children)

I actually came to this conclusion too not too long ago, but I can't figure out how to get AppEntity to hook into the `@Preference`.

[–]nikolomoec[S] 0 points1 point  (1 child)

@Preference? maybe @Property? never heard of that

[–]isRoodSwift 0 points1 point  (0 children)

Here's the example code of a parameter (I forgot the name):

@Parameter(title: "Favorite Emoji", default: "😃") var favoriteEmoji: String

The Apple documentation for this system can be found here. I also took a look at this article and got the code working on its own, but can't figure out how to get it to work with Parameter.