如何在Swift上打印课程名称?
发布时间:2020-12-14 05:51:43 所属栏目:百科 来源:网络整理
导读:参见英文答案 Swift class introspection generics7个答案在斯威夫特,我们不能再使用“self.class”。 我想在NSObject的子类中为description方法打印自己的类名。 如何打印?或者我应该创建新的方法来获取类名称? 我检查了以下问题,但我无法得到答案。 Ho
参见英文答案 >
Swift class introspection & generics7个答案在斯威夫特,我们不能再使用“self.class”。
我想在NSObject的子类中为description方法打印自己的类名。 如何打印?或者我应该创建新的方法来获取类名称? 我检查了以下问题,但我无法得到答案。 How do I print the type or class of a variable in Swift? How do you find out the type of an object (in Swift)? import UIKit class PrintClassName: NSObject { override init() { super.init() println("(self.dynamicType)") // Prints "(Metatype)" println("(object_getClassName(self))"); // Prints "0x7b680910 (Pointer)" println("(self.className)") // Compile error! println(PrintClassName.self) // Prints "(Metatype)" } } 2014.08.25后记 我检查了这个问题。 Swift class introspection & generics 但println(PrintClassName.self)打印“(Metatype)” 我想要获取类名,而不需要在源代码上编写类名。 import Foundation class PrintClassName : NSObject { override init() { super.init() println(NSStringFromClass(self.dynamicType)) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |