SwiftData query returns "private" string in WidgetExtension

Hello,

I am trying to set up Widgets in my app. I want to fetch my data in the SwiftData container that is shared between my app and my WidgetExtension with App Group.

let modelContext = ModelContext(modelContainer)

let predicate = #Predicate<Test>{
    return $0.attribute == true
}
return try modelContext.fetch(FetchDescriptor (predicate: predicate, sortBy: [SortDescriptor(\Test.name)]))

When this code is run in my WidgetExtension, returned objects attributes values are replaced with "<private>" string.

In the logs, Swift Data writes Query returned unrequested identifiers that have been dropped: <private>

Any idea what I might be doing wrong to share my SwiftData between my App and my Widget?

App Groups capability has been added to both apps and extension with the same identifier.

Thank you

Answered by brebispanique in 897910022

I figured it out : it is OSLog that redacts some data.

I am trying to set up Widgets in my app. I want to fetch my data in the SwiftData container that is shared between my app and my WidgetExtension with App Group.

Where do you use App Group? If you are trying to have the widget guy access a data manager class or a view model that managers SwiftData, that's probably not a good approach. What you should use to channel data is the one you have mentioned.

Accepted Answer

I figured it out : it is OSLog that redacts some data.

SwiftData query returns "private" string in WidgetExtension
 
 
Q