问题描述
我正在使用核心数据的Swift应用程序。我创建了 *。xcdatamodeld
文件并创建了一个 NSManagedObject子类
( Editor - > Create NSManagedObject子类...
)。
一切正常,除非我尝试 println
该类的实例化对象(让它调用 Person
)控制台输出空白或简单 Optional()
已解开。
我尝试添加 DebugPrintable
或可打印
类扩展未成功。
这是CoreData对象的已知限制吗?
为了清楚起见,添加代码:
// Person.swift(由Xcode自动生成)
类Person:NSManagedObject {
@NSManaged var firstname:String
@NSManaged var lastname:String
}
我的扩展程序:
/// Person + Helpers.swift
扩展Person:Printable,DebugPrintable {
override var description:String {
returntest
}
override var debugDescription:String {
returndebug test
}
}
控制台打印空行,或者在数组 Person
的情况下,它只打印 [,,,,]
b
$ b
NSLog(我的托管对象:%@,managedObject)
由于某种原因,它不会使用
println
但NSLog
工作很好。I am working on an Swift app with Core Data. I created my
*.xcdatamodeld
file and created aNSManagedObject Subclass
(Editor -> Create NSManagedObject Subclass...
).Everything works fine except when I try to
println
an instantiated object of that class (lets call itPerson
) the console prints blank or simplyOptional()
if not unwrapped.I tried adding
DebugPrintable
orPrintable
via class extension without success.Is this a known limitation of CoreData objects? What am I missing?
Adding code for clarity:
/// Person.swift (auto-generated by Xcode) class Person: NSManagedObject { @NSManaged var firstname: String @NSManaged var lastname: String }
My extension:
/// Person+Helpers.swift extension Person : Printable, DebugPrintable { override var description : String { return "test" } override var debugDescription : String { return "debug test" } }
Console prints empty line, or in the event of an array of
Person
objects, it simply prints[ , , , , ]
解决方案You can use this:
NSLog("My managed object: %@", managedObject)
For some reason, it won't output using
println
butNSLog
works just fine.这篇关于打印NSManagedObject子类Core Data对象到控制台在Swift中返回空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!