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 -

ubuntu - Bash Script to Check That Files Are Being Created -

Php operator `break` doesn't stop while -