Swift
1func propertyNames(className: AnyClass) -> [String] { 2 var propertyNames = [String]() 3 var count: (UInt32, UInt32) = (0, 0) 4 let propertyList = class_copyPropertyList(className, &count.0) 5 6 for i in 0..<Int(count.0) { 7 propertyNames.append("\(NSString(UTF8String: property_getName(propertyList[i]))!)") 8 let attibutes = property_copyAttributeList(propertyList[i], &count.1) 9 for j in 0..<Int(count.1) { 10 if "\(NSString(UTF8String: attibutes[j].name))" == "D" { 11 print("\(propertyNames.last!) is Dynamic") 12 } 13 } 14 } 15 return propertyNames 16}
RuntimeAPIを利用してクラスのプロパティ名を取得しています。各プロパティのAttibuteをチェックし、Dynamic宣言されたプロパティのみStringの配列にappendしreturnしようと試みています。
Swiftで実装しているのですが、
Swift
1NSString(UTF8String: attibutes[j].name)
attibutesの各nameプロパティを出力しても、Dynamic宣言しているプロパティですらDが出力されません。
(確認できたのはT, N, C, R, V 等)
参考にしたのは以下、RealmのRLMProperty.mmのparseObjcPropertyメソッドです。
参考URL: Github - Realm
RuntimeAPIを用いた解決方法でなくても、Mirror Structなどでも結構です。
よろしくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。