Is this possible to call variable dynamically in Objective C?

后端 未结 2 1889
半阙折子戏
半阙折子戏 2020-12-20 08:11

Here is the object, and have following attribute:

NSString attri1;
NSString attri2;
NSString attri3;
NSString attri4;

If I want to list the

2条回答
  •  伪装坚强ぢ
    2020-12-20 08:23

    The feature you're looking for is generally called "variable variables." Objective-C does not have this feature. Actually, most languages don't.

    The good news is that you don't actually need this feature. Four variables named the same thing with a number at the end is basically equivalent to an array, only with the structure being implicit rather than explicit. Just make attri an array and then you can ask it for a numbered item.

提交回复
热议问题