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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

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