Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asserting that an entity has a MOC #232

Merged
merged 1 commit into from Feb 5, 2014
Merged

Asserting that an entity has a MOC #232

merged 1 commit into from Feb 5, 2014

Conversation

notjosh
Copy link
Contributor

@notjosh notjosh commented Feb 5, 2014

I'll save the next poor sucker the hassle of diagnosing this the long way.

(For those playing at home, in my case, when GCC_OPTIMIZATION_LEVEL == 0, it worked fine. I was only getting errors in prod builds. Don't be a fool like me, and keep a reference to your MOC so you can, you know, do work within it.)

robb added a commit that referenced this pull request Feb 5, 2014
Asserting that an entity has a MOC
@robb robb merged commit a4c25f8 into Mantle:master Feb 5, 2014
@robb
Copy link
Member

robb commented Feb 5, 2014

Thanks ✨

@jspahrsummers
Copy link
Member

I think it's legal to have a managed object without a context. Especially for this use, where you just want to parse a MTLModel out of it, it seems reasonable to allow that.

@notjosh
Copy link
Contributor Author

notjosh commented Feb 5, 2014

Actually, yeah, you're right. That's a very valid use case. However, without a valid context, the innards of performInContext() won't do a whole lot.

To cater for that use case, you'd have to check for nil and executing the block param directly to get something meaningful back. I wonder if that'd have solved my issue? I'm not sure if that'll have undesired side-effects though.

@robb
Copy link
Member

robb commented Feb 5, 2014

Sorry, I'll revert the commit

@notjosh
Copy link
Contributor Author

notjosh commented Feb 5, 2014

Actually, given that NSConfinementConcurrencyType is 0, the block will run despite context being nil. So you're right, this is probably better off without the assert for that one use case.

I still think it would make sense to address the problematic use case though. So, maybe instead have an assert that checks -[NSManagedObject isFault] as well as nil context? AFAIK, it will only ever fault if there's persisted data we need to access, in which case it needs a context.

robb added a commit that referenced this pull request Feb 5, 2014
Reverts my premature merge in #232 😓
@jspahrsummers
Copy link
Member

👍 on isFault.

Let's also add explicit checks for context == nil with performInContext() too. I don't like depending on the value of NSConfinementConcurrencyType.

@notjosh notjosh deleted the patch-1 branch February 6, 2014 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants