Skip to content

Instantly share code, notes, and snippets.

@bgrace
Last active August 29, 2015 14:09
Show Gist options
  • Save bgrace/021f55a9f160685e2433 to your computer and use it in GitHub Desktop.
Save bgrace/021f55a9f160685e2433 to your computer and use it in GitHub Desktop.
Printable on NSManaged Object doesn't get invoked.
// See notes in first comment
if let moc = AppDelegate.instance.managedObjectContext {
// fetching NSManagedObject with fancy generic typesafe helper method
if let allGrowers = moc.fetch(Grower.self, predicate: nil, sortDescriptors: nil, returnsObjectsAsFaults: true) {
switch allGrowers {
case .Value(let b):
let allGrowers = b.contents
for grower in allGrowers {
println("\(grower.name) -> \(grower)")
}
case .Error(let e):
println("Couldn't fetch all growers because \(e)")
}
}
// fetching the objects as simply as possible
let request = NSFetchRequest(entityName: "Grower")
let result = moc.executeFetchRequest(request, error: nil)
println("Raw result:")
println(result)
}
///// Extension for the Grower object:
extension Grower : NamedEntity {
class var entityName: String {
return "Grower"
}
override var description: String {
return self.name
}
override var debugDescription: String {
return "Debug: \(self.name)"
}
}
@tualatrix
Copy link

Me too. I tried to print single object, it just returned:

{
CoreData.NSManagedObject = {
ObjectiveC.NSObject = {}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment