Hi, Cristosv
Hope you can help me understand whatI'm doing wrong.
I have shared the CoreData with widget and follow your instruction so I have this situation now
struct DictaWordWidget: Widget {
let kind: String = "DictaWordWidget"
var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "DictaWord")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
print(storeDescription)
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy
return container
}()
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider(context: persistentContainer.viewContext)) { entry in
WidgetView(entry: entry)
}
.supportedFamilies([.systemMedium, .systemLarge])
.configurationDisplayName("My Widget")
.description("This is an example widget.")
}
}
so after in the provider the situation is like this
struct Provider: TimelineProvider {
var managedObjectContext : NSManagedObjectContext
typealias Entry = SimpleEntry
init(context : NSManagedObjectContext) {
print("init provider")
self.managedObjectContext = context
}
and finally in the getTimeline
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let request = NSFetchRequest<WordEntity>(entityName: "WordEntity")
do {
let words = try managedObjectContext.fetch(request)
let oneWord = Array(words.prefix(1))
let entry = SimpleEntry(date: .now, words: oneWord)
print("result: \(words)")ì
let timeline = Timeline(entries: [entry], policy: .after(.now.advanced(by: 60 * 60 * 30)))
completion(timeline)ì
} catch let error {
print("Error fetching coredata words: \(error.localizedDescription)")
}
}
my SimpleEntry
struct SimpleEntry: TimelineEntry {
let date: Date
let words: [WordEntity]
}
but when result is printed the array is empty and I really not understand why. All seams correct at code side no runtime error
thanks
Post
Replies
Boosts
Views
Activity
Have you found out how and if it's possible to access to the sensor datas? thanks
Even on Sonoma RC Xcode 14.3.1 doesn't work!!! Next week it's plan to make Xcode work again with the official release?