ios - Swift / Objective C: How to get value from object by string name -



ios - Swift / Objective C: How to get value from object by string name -

class { var x = 1 } var = a()

how variable "x" object "a" using string name ( a["x"] )?

this work if class inherits nsobject, can utilize valueforkey: @ properties.

import foundation class a: nsobject { var x = 1 } allow = a() allow aval = a.valueforkey("x") println("\(aval)")

note aval anyobject? here since there's no type information. you'll need cast or test yourself.

ios objective-c xcode swift

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -