-
Notifications
You must be signed in to change notification settings - Fork 76
Add main queue child contexts of the main queue MOC #130
Conversation
👀 @Jobot |
public func newChildContext(concurrencyType concurrencyType: NSManagedObjectContextConcurrencyType = .PrivateQueueConcurrencyType, | ||
name: String? = "Main Queue Context Child") -> NSManagedObjectContext { | ||
switch concurrencyType { | ||
case .MainQueueConcurrencyType where !NSThread.isMainThread(): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Looks good. |
|
||
- returns: `NSManagedObjectContext` The new worker context. | ||
*/ | ||
public func newChildContext(concurrencyType concurrencyType: NSManagedObjectContextConcurrencyType = .PrivateQueueConcurrencyType, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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