iterate over object class attributes in Swift

前端 未结 5 1987
星月不相逢
星月不相逢 2020-11-30 01:28

Is there a Simple way in Swift to iterate over the attributes of a class.

i.e. i have a class Person, and it has 3 attributes: name, lastname, age.

is there

5条回答
  •  余生分开走
    2020-11-30 01:55

    Apple didn't remove reflect,they just change it to _reflect,they also changed MirrorType to _MirrorType.
    The Swift 2.0 version of @Teemu Kurppa 's code:

    func print_properties(mirror: _MirrorType) {
      for i in 0..

提交回复
热议问题