Post

Replies

Boosts

Views

Activity

Reply to SwiftData @Model does not conform to the 'Sendable' protocol; thi
@FPST I had to write a method that returned the models from a sorted fetch and then get their PersistentIdentifiers. public func fetchSort<T: PersistentModel>(_ descriptor: FetchDescriptor<T>) throws -> [PersistentIdentifier] { var result = [PersistentIdentifier]() var models = [T]() models = try self.modelContext.fetch(descriptor) for model in models { let pID = model.persistentModelID result.append(pID) } return result }
Topic: App & System Services SubTopic: iCloud Tags:
Aug ’24
Reply to Swift 6, SwiftData modelContext.save() Crashes, Does not AutoSave
I've discovered where the crash is occurring. I have an @objc function called updateView() that is fired when the view controller detects NSPersistenStoreRemoteChange. As soon as I save an object in another view, the update fires and the app crashes. NotificationCenter.default.addObserver(self, selector: #selector(updateView(_ :)), name: .NSPersistentStoreRemoteChange, object: nil) The crash does not occur using Swift 5.
Topic: App & System Services SubTopic: iCloud Tags:
Aug ’24
Reply to Main actor-isolated instance method 'locationManagerDidChangeAuthorization' cannot be used to satisfy nonisolated protocol requirement
@DTS Engineer, here's an example of what I did. nonisolated func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { Task { await changeMyLocation(locations) } } func changeMyLocation(_ locations: [CLLocation]) { myLocation = locations.last } I created a function to change the location and called it via a task.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’24
Reply to SwiftData @Model does not conform to the 'Sendable' protocol; thi
@FPST I had to write a method that returned the models from a sorted fetch and then get their PersistentIdentifiers. public func fetchSort<T: PersistentModel>(_ descriptor: FetchDescriptor<T>) throws -> [PersistentIdentifier] { var result = [PersistentIdentifier]() var models = [T]() models = try self.modelContext.fetch(descriptor) for model in models { let pID = model.persistentModelID result.append(pID) } return result }
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Aug ’24
Reply to Swift 6, SwiftData modelContext.save() Crashes, Does not AutoSave
I've discovered where the crash is occurring. I have an @objc function called updateView() that is fired when the view controller detects NSPersistenStoreRemoteChange. As soon as I save an object in another view, the update fires and the app crashes. NotificationCenter.default.addObserver(self, selector: #selector(updateView(_ :)), name: .NSPersistentStoreRemoteChange, object: nil) The crash does not occur using Swift 5.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Aug ’24
Reply to Main actor-isolated instance method 'locationManagerDidChangeAuthorization' cannot be used to satisfy nonisolated protocol requirement
@DTS Engineer, here's an example of what I did. nonisolated func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { Task { await changeMyLocation(locations) } } func changeMyLocation(_ locations: [CLLocation]) { myLocation = locations.last } I created a function to change the location and called it via a task.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’24