zoukankan      html  css  js  c++  java
  • swit4 获取属性列表

    class People: NSObject {

        

        var name:String?

        

        var age:Int = 0

        

        var title:String?

        

        

    //    override init() {

    //      //  name="dffe"

    //

    //       // let <#name#> = <#value#>

    //        let cont = UInt32()

    //

    //

    //        class_copyIvarList(self, &cont)

    //      //  super.init()

    //

    //    }

    //

      class  func propretyList() ->[String] {

            

        var cont:UInt32 = 4

        //这个在switf4中不行

      //  let list = class_copyPropertyList(self, &cont)

        let list = class_copyIvarList(self, &cont)

            

         print("属性个数(cont)")

        

      //  print(list ?? <#default value#>)

            

            for i in 0..<Int(cont) {

                

                let pty = list?[i]

                //获取属性的名称<C语言字符串>

                //转换过程:Int8 -> Byte -> Char -> C语言字符串

                //let cName = property_getName(pty!)

                let cName = ivar_getName(pty!)

                //转换成String的字符串

                let name = String(utf8String: cName!)

                print(name!)

                

                

                

                

                

                

                

            }

              free(list) //释放list

            

            return []

        }

        

    //    init(name:String) {

    //        

    //        self.name=name

    //        

    //        //super.init()

    //    }

    //    

    }

    一天一章
  • 相关阅读:
    Apache配置
    linux centos使用xrdp远程界面登陆
    实现台式机redhat6.4无线网卡上网RTL8188CUS
    linux-redhat6.4驱动无线网卡rtl8188eu
    linux开机自动连接无线网络
    javascript for循环 日期 select
    amazeui折叠面板智能化展开
    PHP Ueditor 富文本编辑器
    vue.js 使用小结
    php mysqli mysqli_query() mysqli_real_query()
  • 原文地址:https://www.cnblogs.com/hangman/p/8403825.html
Copyright © 2011-2022 走看看