Swift Runtime探索,Error定义使用
我们⽤下⾯这段代码来测试⼀下:
class LGTeacher {
var age: Int = 18
func teach(){
print("teach")
}
}
let t = LGTeacher()
func test(){
var methodCount:UInt32 = 0
let methodlist = class_copyMethodList(LGTeacher.self, &method Count)
for i in 0..<numericCast(methodCount) {
if let method = methodlist?[i]{
let methodName = method_getName(method);
print("⽅法列表:\(String(describing: methodName))")
}else{
print("not found method");
}
}
var count:UInt32 = 0
let proList = class_copyPropertyList(LGTeacher.self, &count)
for i in 0..<numericCast(count) {
if let property = proList?[i]{
let propertyName = property_getName(property);
print("属性成员属性:\(String(utf8String: propertyName)! )")
}else{
print("没有找到你要的属性");
}
}
}
运⾏这段代码你会发现,当前不管是我们的⽅法列表还是我们的属性列表,此次此刻都是为空的。
@objc 的标识,如果这个时候我们将我们当前的⽅法和属性添加上,会发⽣什么?
此刻代码会输出我们当前的 teach ⽅法和 age 属性。但是此刻对于我们的 OC 来说是没有办法使⽤的:
所以这⾥我们得出来这样⼀个结论&#