Swift 3.0 Runtime Get class properties

Source: Internet
Author: User
Tags uikit

In OC, there is no absolute private and can be removed with runtime.

In swift, there is absolute private, with private decoration, is unable to take out.

Here's how swift gets the class properties:

//
Person.swift
//

Import UIKit

Class Person:nsobject {
var name:string?
var age:int = 0
Private var title:string?

Class Func propertylist () {

var count:uint32 = 0

Let list = Class_copypropertylist (self, &count)

For I in 0..<int (count) {
Let pty = list? I

Let CName = Property_getname (pty)

Let name = String (utf8string:cname!)

Print (name)

}
Free (list)
}
}

Called in the Controller
Viewcontroller.swift
//


Import UIKit

Class Viewcontroller:uiviewcontroller {

Override Func Viewdidload () {
Super.viewdidload ()
Person.propertylist ()
}
}

Output Result:

Optional ("name")
Optional ("Age")

Swift 3.0 Runtime Get class properties

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.