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)" | |
} | |
} |
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
In response to the Stackoverflow question: http://stackoverflow.com/questions/26599493/printing-nsmanagedobject-subclassed-core-data-object-to-console-returns-empty-li and in particular the first comment.
I'm using Xcode 6.1 and developing against the iOS 8.1 SDK.
This code should fetch all objects of type Grower, and print them. Instead, the
description
method is never called. I demonstrate this fetching the objects in two different ways.Note:
returnObjectsAsFaults
istrue
orfalse
description
method and get the expected result back.Grower
or leave it asNSManagedObject
.The output for
println("\(grower.name) -> \(grower)")
is always:EXAMPLE VINEYARDS ->
The output for dumping the whole array is always:
I'm pretty new to CoreData. Is it a bug or am I doing it wrong?