如何从可用字符串中选择随机字符串

时间:2014-04-28 08:27:33

标签: ios objective-c nsstring sprite-kit

我有一些字符串。

NSString *st1 = @"png1";
NSString *st2 = @"png2";
NSString *st3 = @"png3";

我有一个SKTexture

SKTexture *Texture = [SKTexture textureWithImageNamed: @"????"];

如何选择来自st1st2st3的随机字符串" ????"。

我用arc4random尝试了它,它只适用于整数,但是使用字符串我无法解决我的问题。

有人能帮帮我吗?谢谢你的回答。

1 个答案:

答案 0 :(得分:3)

NSArray *a = @[st1, st2, st3];
SKTexture *Texture = [SKTexture textureWithImageNamed: a[arc4random_uniform(a.count)]];