Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env cato 1.2
import Foundation
class OptCls: NSObject {
dynamic var s: String?
dynamic var nos: String = ""
dynamic var nss: NSString?
dynamic var ius: String!
dynamic var i: Int = 0
dynamic var o = NSObject()
dynamic var oo: OptCls?
extension Optional {
var getT: Any.Type {
return T.self
func getOptionalPropertyNames(object: AnyObject) -> NSDictionary {
let reflection = reflect(object)
var properties = [String:String]()
// Skip the first property (super):
// super is an implicit property on Swift objects
for i in 1..<reflection.count {
println("reflection: \(reflection[i])")
// let prop = class_getProperty(object.dynamicType, reflection[i].0)
// println(String.fromCString(property_getAttributes(prop)))
let mirror = reflection[i].1
let valueType = mirror.valueType
println("value type: \(valueType)")
if mirror.disposition == .Optional {
properties[reflection[i].0] = toString(valueType)
return properties
let props = getOptionalPropertyNames(OptCls())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment