Skip to content

Commit

Permalink
fix for model specified fetch requests
Browse files Browse the repository at this point in the history
there may be more, but these are the changes I found when having a fetch request specified in the model
  • Loading branch information
dave256 committed Apr 3, 2015
1 parent dac6435 commit 1542d92
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions templates/machine.swift.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ class _<$managedObjectClassName$>: <$customSuperentity$> {
return self.fetch<$FetchRequest.name.initialCapitalString$>(managedObjectContext<$foreach Binding FetchRequest.bindings do2$>, <$Binding.name$>: <$Binding.name$><$endforeach do2$>, error: nil)
}

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 substitutionVariables = [<$if FetchRequest.hasBindings$><$foreach Binding FetchRequest.bindings do2$>
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 substitutionVariables : [NSObject : AnyObject] = [<$if FetchRequest.hasBindings$><$foreach Binding FetchRequest.bindings do2$>
"<$Binding.name$>": <$Binding.name$>,
<$endforeach do2$><$else$>:<$endif$>]

let fetchRequest = model.fetchRequestFromTemplateWithName("<$FetchRequest.name$>", substitutionVariables: substitutionVariables)
assert(fetchRequest != nil, "Can't find fetch request named \"<$FetchRequest.name$>\".")

var error: NSError? = nil
let results = managedObjectContext.executeFetchRequest(fetchRequest, error: &error)
let results = managedObjectContext.executeFetchRequest(fetchRequest!, error: &error)

if error != nil {
outError.memory = error
Expand Down

0 comments on commit 1542d92

Please sign in to comment.