美文网首页
swift 打印属性列表

swift 打印属性列表

作者: East_Coast | 来源:发表于2018-04-13 09:52 被阅读67次
    
    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")
        }
    }
    
    
    

    相关文章

      网友评论

          本文标题:swift 打印属性列表

          本文链接:https://www.haomeiwen.com/subject/qkaqkftx.html