TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Fetching an entity as a dictionary, and including a related entity in the result

Forums > Swift

Thanks to the astonishing stupidity of NSManagedObjectContext.perform() async throws, I can't make additional async calls in the perform block. So I’m having to jump through extraordinary hoops to work with my entities.

One of the things I’m doing is returning a dictionary representation of my fetched entity using .resultType = .dictionaryResultType. But my entity has a related entity, and none of that is being included in the fetched results (normally it would fault in when you accessed it via the related property).

Is there a way to tell the request that I want to include the whole related entity (but not its relations) in the result dictionary? I tried setting propertiesToFetch, but that returned an object ID for the related entity. I can go make another fetch request for that, but that makes it even more unwieldy.

I'm doing all of this on a dedicated background context, which gets its own queue. There is no excuse for Apple not allow async calls inside that perform block.

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.