Found a solution! Can refer to sample code here for solution: https://developer.apple.com/documentation/coredata/adopting_swiftdata_for_a_core_data_app to use multiple entity and to preview your UI in XCode Canvas.
Post
Replies
Boosts
Views
Activity
Thank you very much! Ya, it works now!
Thank you for the reply @Jineshsethia, I'm only fetching the current date sunEvents and the latitude and longitude details are available in let journalingWeather = CLLocation(latitude: latitude, longitude: longtitude). Could you advise how to use the decoder?
Thank you Ricob.
Created a new func in CoreDataStack without async to save data from Shortcuts and all data are saved in CoreDataStack successfully.
func handle(intent: CreateNoteIntent, completion: @escaping (CreateNoteIntentResponse) -> Void) {
let title = intent.title!
let isBookmark = intent.isBookmark!
/// Access core data stack `Data` to save the note contents
var dataProvider: datasProvider = .shared
dataProvider.addDataFromShortcut(time: Date(), title: title, isFavorite: isBookmark as! Bool)
let response = CreateNoteIntentResponse(code: .success, userActivity: nil)
completion(response)
}
Found a solution to persist data in Edit Mode. In your Edit View
// Core Data Model
@ObservedObject var data: Data
// Your Text Field
@State private var titleInput: String = ""
NavigationView {
Form {
TextEditor(text: $titleInput)
}
}
.onAppear {
self.titleInput = self.data.title
}
Found a guide in WWDC 2021: https://developer.apple.com/videos/play/wwdc2021/10017/