Bring Core Data concurrency to Swift and SwiftUI

RSS for tag

Discuss the WWDC21 session Bring Core Data concurrency to Swift and SwiftUI.

Posts under wwdc21-10017 tag

25 Posts

Post

Replies

Boosts

Views

Activity

How to await for async stuff within a moc.perform block
I want to implement this pattern in my app: let moc = ...newBackgroundContext() try await moc.perform { // test for existence of a specific object in the moc if !objectExists { let apiObject = await api.fetchObjectFromNetwork() // create managed object from apiObject try moc.save() } } Unfortunately, I am unable to await my network call because the moc.perform block is not async. So far, I've come up with this solution: let moc = ...newBackgroundContext() try await moc.perform { // test for existence of a specific object in the moc if !objectExists { Task { let apiObject = await api.fetchObjectFromNetwork() try await moc.perform { // create managed object from apiObject try moc.save() } } } } But it doesn't feel quite right. What do you think? Am I on the right track, or am I introducing unneeded complexity?
0
0
634
Aug ’21
Update Error
Update Error BigSur Beta > Finding available software Downloading macOS Big Sur 11.5 Beta 2 Password: Downloading: 100.00% Failed to download & prepare update: Error Domain=SUMacControllerError Code=7721 "[SUMacControllerErrorPreflightWakeupFailed=7721] Failed to perform PreflightWakeup operation: [MobileSoftwareUpdateErrorDomain(MSU):819]" UserInfo={NSUnderlyingError=0x127908c80 {Error Domain=MobileSoftwareUpdateErrorDomain Code=819 "softwareupdated relaunch needed to load new brain" UserInfo={NSDebugDescription=softwareupdated relaunch needed to load new brain}}, SUMacControllerErrorIndicationsMask=0, NSDebugDescription=[SUMacControllerErrorPreflightWakeupFailed=7721] Failed to perform PreflightWakeup operation: [MobileSoftwareUpdateErrorDomain(MSU):819], NSLocalizedDescription=Failed to launch the software update installer. Please try again.} https://store-028.blobstore.apple.com/v01/FR/0433/8681/0000/16782909/sysdiagnose_2021.06.06_15-45-23%2B0000_macOS_MacBookAir10-1_20G5023d.tar.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=MKIA0879Y5FEZQ0RYD6Z%2F20210608%2Fstore-028%2Fs3%2Faws4_request&X-Amz-Date=20210608T164714Z&X-Amz-Expires=15&X-Amz-SignedHeaders=host&X-Amz-Signature=70a6152d9b55d98b7e487329fa2813a95770fe8dd489cea7a7e0aed32a838bb1 24/12HR , >> DAY WEEK YEAR . WEEK DAY YEAR << US & EU ,,
1
0
949
Aug ’21
Using unmanaged core data properties as section identifiers
Let's say I have a Person entity in my core data model that has a name attribute of type String. I want to use a sectioned fetch request to list my Person entities sectioned by the first letter of their name. I wrongly assumed I could just add a property to my NSManagedObject subclass and use it in a sectioned fetch request as follows extension Person { var firstLetterOfName: String { // get the first letter } } @SectionedFetchRequest(     sectionIdentifier: \.firstLetterOfName,     sortDescriptors: [ SortDescriptor(\.name, order: .forward) ]) var people: SectionedFetchResults<String, Person> However, I end up with an uncaught exception NSUnknownKeyException How can I define this property in a way that I can use it in the section identifier?
1
0
1.1k
Aug ’21
@SectionedFetchRequest using relationship as sectionIdentifier
As the title says I'm trying to use a to-one relationship as a sectionIdentifier in a @SectionedFetchRequest. The compiler is happy but there's a runtime crash: Could not cast value of type '_NSCoreDataTaggedObjectID' (0x146c0f750) to 'MyApp.ServiceCategory' (0x104c4b3a0). The fetch request: @SectionedFetchRequest(     sectionIdentifier: \Service.serviceCategory,     sortDescriptors: [       SortDescriptor(\Service.active, order: .reverse),       SortDescriptor(\Service.displayText)     ],     predicate: NSPredicate(format: "%K = %d", #keyPath(Service.active), true),     animation: .default   ) var sectionedServices: SectionedFetchResults<ServiceCategory?, Service> ... and the breaking runtime code: ForEach(sectionedServices /* here */) { section in Section(header: Text(section.id?.displayText ?? "")) { ForEach(section) { svc in Text(svc.displayText ?? "") } } } The request works if I switch out the sectionIdentifier for the active property (which is a Bool property rather than a relationship). It also works if I switch it out for displayText which is an optional String, so it seems to be a problem trying to section by a relationship rather than with it being an optional. The error suggests the request is returning a Core Data fault rather than an object but my attempts to somehow unwrap this haven't gone very far. Any thoughts would be greatly appreciated!
4
0
2.4k
Jul ’21
How to await for async stuff within a moc.perform block
I want to implement this pattern in my app: let moc = ...newBackgroundContext() try await moc.perform { // test for existence of a specific object in the moc if !objectExists { let apiObject = await api.fetchObjectFromNetwork() // create managed object from apiObject try moc.save() } } Unfortunately, I am unable to await my network call because the moc.perform block is not async. So far, I've come up with this solution: let moc = ...newBackgroundContext() try await moc.perform { // test for existence of a specific object in the moc if !objectExists { Task { let apiObject = await api.fetchObjectFromNetwork() try await moc.perform { // create managed object from apiObject try moc.save() } } } } But it doesn't feel quite right. What do you think? Am I on the right track, or am I introducing unneeded complexity?
Replies
0
Boosts
0
Views
634
Activity
Aug ’21
Update Error
Update Error BigSur Beta > Finding available software Downloading macOS Big Sur 11.5 Beta 2 Password: Downloading: 100.00% Failed to download & prepare update: Error Domain=SUMacControllerError Code=7721 "[SUMacControllerErrorPreflightWakeupFailed=7721] Failed to perform PreflightWakeup operation: [MobileSoftwareUpdateErrorDomain(MSU):819]" UserInfo={NSUnderlyingError=0x127908c80 {Error Domain=MobileSoftwareUpdateErrorDomain Code=819 "softwareupdated relaunch needed to load new brain" UserInfo={NSDebugDescription=softwareupdated relaunch needed to load new brain}}, SUMacControllerErrorIndicationsMask=0, NSDebugDescription=[SUMacControllerErrorPreflightWakeupFailed=7721] Failed to perform PreflightWakeup operation: [MobileSoftwareUpdateErrorDomain(MSU):819], NSLocalizedDescription=Failed to launch the software update installer. Please try again.} https://store-028.blobstore.apple.com/v01/FR/0433/8681/0000/16782909/sysdiagnose_2021.06.06_15-45-23%2B0000_macOS_MacBookAir10-1_20G5023d.tar.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=MKIA0879Y5FEZQ0RYD6Z%2F20210608%2Fstore-028%2Fs3%2Faws4_request&X-Amz-Date=20210608T164714Z&X-Amz-Expires=15&X-Amz-SignedHeaders=host&X-Amz-Signature=70a6152d9b55d98b7e487329fa2813a95770fe8dd489cea7a7e0aed32a838bb1 24/12HR , >> DAY WEEK YEAR . WEEK DAY YEAR << US & EU ,,
Replies
1
Boosts
0
Views
949
Activity
Aug ’21
Using unmanaged core data properties as section identifiers
Let's say I have a Person entity in my core data model that has a name attribute of type String. I want to use a sectioned fetch request to list my Person entities sectioned by the first letter of their name. I wrongly assumed I could just add a property to my NSManagedObject subclass and use it in a sectioned fetch request as follows extension Person { var firstLetterOfName: String { // get the first letter } } @SectionedFetchRequest(     sectionIdentifier: \.firstLetterOfName,     sortDescriptors: [ SortDescriptor(\.name, order: .forward) ]) var people: SectionedFetchResults<String, Person> However, I end up with an uncaught exception NSUnknownKeyException How can I define this property in a way that I can use it in the section identifier?
Replies
1
Boosts
0
Views
1.1k
Activity
Aug ’21
@SectionedFetchRequest using relationship as sectionIdentifier
As the title says I'm trying to use a to-one relationship as a sectionIdentifier in a @SectionedFetchRequest. The compiler is happy but there's a runtime crash: Could not cast value of type '_NSCoreDataTaggedObjectID' (0x146c0f750) to 'MyApp.ServiceCategory' (0x104c4b3a0). The fetch request: @SectionedFetchRequest(     sectionIdentifier: \Service.serviceCategory,     sortDescriptors: [       SortDescriptor(\Service.active, order: .reverse),       SortDescriptor(\Service.displayText)     ],     predicate: NSPredicate(format: "%K = %d", #keyPath(Service.active), true),     animation: .default   ) var sectionedServices: SectionedFetchResults<ServiceCategory?, Service> ... and the breaking runtime code: ForEach(sectionedServices /* here */) { section in Section(header: Text(section.id?.displayText ?? "")) { ForEach(section) { svc in Text(svc.displayText ?? "") } } } The request works if I switch out the sectionIdentifier for the active property (which is a Bool property rather than a relationship). It also works if I switch it out for displayText which is an optional String, so it seems to be a problem trying to section by a relationship rather than with it being an optional. The error suggests the request is returning a Core Data fault rather than an object but my attempts to somehow unwrap this haven't gone very far. Any thoughts would be greatly appreciated!
Replies
4
Boosts
0
Views
2.4k
Activity
Jul ’21
Alternative ideas for NSBatchInsertRequest to set relationships
Hi everybody, I know that NSBatchInsertRequest doesn't let you to set the relationship between Entities. And if you try to set Xcode gets angry and says you that the problem is that record is in other context and you can't modify it. So, Anyone knows any solution, alternative to solve this problem? thank you
Replies
0
Boosts
0
Views
905
Activity
Jun ’21