From 43f61d066d9daa65d6f941e01b9c0be8e56afb28 Mon Sep 17 00:00:00 2001 From: Tom Harrington Date: Tue, 28 Apr 2015 20:57:01 -0600 Subject: [PATCH] Optional fixes for fetch requests stored in managed object model --- templates/machine.swift.motemplate | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/machine.swift.motemplate b/templates/machine.swift.motemplate index c5ccbdb5..572defdc 100644 --- a/templates/machine.swift.motemplate +++ b/templates/machine.swift.motemplate @@ -98,7 +98,7 @@ class _<$managedObjectClassName$>: <$customSuperentity$> { } class func fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext: NSManagedObjectContext!<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.type$><$endforeach do2$>, error outError: NSErrorPointer) -> AnyObject? { - let model = managedObjectContext.persistentStoreCoordinator().managedObjectModel() + let model = managedObjectContext.persistentStoreCoordinator!.managedObjectModel let substitutionVariables = [<$if FetchRequest.hasBindings$><$foreach Binding FetchRequest.bindings do2$> "<$Binding.name$>": <$Binding.name$>, <$endforeach do2$><$endif$> ] @@ -108,22 +108,22 @@ class _<$managedObjectClassName$>: <$customSuperentity$> { var error: NSError? = nil var result: AnyObject? = nil - let results = managedObjectContext.executeFetchRequest(fetchRequest, error: &error) + let results = managedObjectContext.executeFetchRequest(fetchRequest!, error: &error) if error != nil { outError.memory = error } else { - switch results.count { + switch results!.count { case 0: // Nothing found matching the fetch request. That's cool, though: we'll just return nil. break case 1: - result = results[0] + result = results![0] default: NSLog("WARN fetch request <$FetchRequest.name$>: 0 or 1 objects expected, %lu found (substitutionVariables:%@, results:%@)", - results.count, + results!.count, substitutionVariables, - results); + results!); } }