Skip to content
This repository has been archived by the owner on Jun 2, 2018. It is now read-only.

Add main queue child contexts of the main queue MOC #130

Merged
merged 3 commits into from
Apr 26, 2016

Conversation

rcedwards
Copy link
Contributor

@rcedwards rcedwards commented Apr 22, 2016

Summary of Changes

Gives the API consumer the ability to create an NSManagedObjectContext with MainQueueConcurrencyType as a child of the Main Queue Context.

Addresses

#127

@rcedwards rcedwards changed the title Rcedwards/mainqueue child mocs Add main queue child contexts of the main queue MOC Apr 22, 2016
@wolfbrain
Copy link

👀 @Jobot

public func newChildContext(concurrencyType concurrencyType: NSManagedObjectContextConcurrencyType = .PrivateQueueConcurrencyType,
name: String? = "Main Queue Context Child") -> NSManagedObjectContext {
switch concurrencyType {
case .MainQueueConcurrencyType where !NSThread.isMainThread():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a guard would be a better choice here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I better understand how your discriminating here I'm having trouble seeing how this would be written with guard. So, your first instinct was probably right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm perhaps.

Do you think this reads better?

guard !(concurrencyType == .MainQueueConcurrencyType && !NSThread.isMainThread()) else {
    preconditionFailure("Main thread MOCs must be created on the main thread")
}

I don't like having to put a bang around the entire statement but I also like that it doesn't have a default: break

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just use an if to avoid inverting the logic:

if concurrencyType == .MainQueueConcurrencyType && !NSThread.isMainThread() {
    preconditionFailure("Main thread MOCs must be created on the main thread")
}

In fact, you can just use precondition and put it all in one handy statement.

@Jobot
Copy link

Jobot commented Apr 25, 2016

Looks good.
👍


- returns: `NSManagedObjectContext` The new worker context.
*/
public func newChildContext(concurrencyType concurrencyType: NSManagedObjectContextConcurrencyType = .PrivateQueueConcurrencyType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the name of this function have something about Main in it for self-documenting purposes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this function vends you a new managed object context that is a child of the main queue context, but doesn't' necessarily itself be a main queue context. In fact it defaults to a private queue context so I don't think main is necessary in the function name.

@rcedwards rcedwards merged commit 2b4d25e into master Apr 26, 2016
@rcedwards rcedwards deleted the rcedwards/mainqueue_child_mocs branch April 26, 2016 13:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants