swift 打印属性列表

2018-04-13  本文已影响67人  East_Coast

func LogIvarList(classString:String){
    
    print("\n\n ********** \(classString)  IvarList ****************\n")
    
    var count:UInt32 = 0
    let list = class_copyIvarList(NSClassFromString(classString), &count)
    for i in 0 ..< Int(count) {
        let ivar = list![i]
        let name = ivar_getName(ivar)
        let type = ivar_getTypeEncoding(ivar)
        print( String(cString: name!),"-----",String(cString: type!),"\n")
    }
}


func LogPropertyList(classString:String){
    
    print("\n\n ********** \(classString)  PropertyList ****************\n")
    var count:UInt32 = 0
    let list = class_copyPropertyList(NSClassFromString(classString), &count)
    for i in 0 ..< Int(count) {
        let property = list![i]
        let name = property_getName(property)
        let type = property_getAttributes(property)
        print( String(cString: name!),"------",String(cString: type!),"\n")
    }
}


上一篇 下一篇

猜你喜欢

热点阅读