Swift 5 动态获取一个类的属性,方法,和变量

1、获取一个类的所有属性

func getAllPropertys(view: Any?) -> [String] {
    var result = [String]()
    let count = UnsafeMutablePointer.allocate(capacity: 0)
    let buff = class_copyPropertyList(object_getClass(view), count)
    let countInt = Int(count[0])
    for i in 0..

2、获取一个类的成员变量

func getAllIvarList(view: Any?) -> [String] {
    var result = [String]()
    let count = UnsafeMutablePointer.allocate(capacity: 0)
    let buff = class_copyIvarList(object_getClass(view), count)
    let countInt = Int(count[0])
    for i in 0..

你可能感兴趣的:(Swift 5 动态获取一个类的属性,方法,和变量)