Last active
August 29, 2015 14:09
-
-
Save bgrace/021f55a9f160685e2433 to your computer and use it in GitHub Desktop.
Printable on NSManaged Object doesn't get invoked.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Me too. I tried to print single object, it just returned:
{
CoreData.NSManagedObject = {
ObjectiveC.NSObject = {}
}
}