I can't get properties of a Class using swift by class_copyPropertyList

ios, properties, swift

Solution

You need to make sure your class subclasses from NSObject, or add @objc in front of your class name (which internally does the same I believe).

The class_copyPropertyList method will only work on NSObject subclasses, which Swift classes don't derive from.

Problem

``` class func getPropertiesInfo() -> (propertiesName:[String], propertiesType:[String]) { var propertiesName:[String] = Array(); var propertiesType:[String] = Array(); var outCount:UInt32 = 0; var i:Int = Int(); var properties:UnsafePointer<objc_property_t> = class_copyPropertyList(object_getClass(self), &outCount); println("\(outCount)"); } ``` I using: ``` var infos = Model.getPropertiesInfo(); println("names = \(infos.propertiesName)"); println("types = \(infos.propertiesType)"); ``` `Model` is my custom Class, has properties `name`(String) and `age`(int). But i get nothing,

Original source