michaelarmstrong / SuperRecord

A small set of utilities to make working with CoreData and Swift a bit easier.
MIT License
366 stars 27 forks source link

Removed duplicate functions using optional values #2

Closed PGLongo closed 10 years ago

PGLongo commented 10 years ago

Hi!

I have removed all:

let context = SuperCoreDataStack.defaultStack.managedObjectContext!

using swift optional values, so functions like

class func findFirstOrCreateWithAttribute(attribute: NSString!, value: NSString!, context: NSManagedObjectContext) -> NSManagedObject 

Became

class func findFirstOrCreateWithAttribute(attribute: NSString!, value: NSString!, context: NSManagedObjectContext = SuperCoreDataStack.defaultStack.managedObjectContext!) -> NSManagedObject 
michaelarmstrong commented 10 years ago

nice! The deleteAll() and deleteAll(context:) etc can be reduced to a single method that will handle both situations. Thanks for contributing already.

could it be improved further by possibly by doing the following?

context: NSManagedObjectContext! = SuperCoreDataStack.defaultStack.managedObjectContext!

becomes

(at the top somewhere) var initializedContext = SuperCoreDataStack.defaultStack.managedObjectContext!

context: NSManagedObjectContext! = initializedContext

i.e. extract the optional value into a variable (the reason I ask is because i'm currently rewriting the SuperCoreDataStack class to be decent rather than the standard boilerplate and it'll support the new architecture.

PGLongo commented 10 years ago

It depends on how you rewrite SuperCoreDataStack.

PGLongo commented 10 years ago

@michaelarmstrong should I do something?