Pregunta

I have a few strings.

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

And I have a SKTexture.

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

How can I choose a random string from st1, st2 and st3 at "????".

I tried it with arc4random, it worked only with integer, but with string I couldn't solve my problem.

Can anyone help me please? Thanks for answers.

¿Fue útil?

Solución

NSArray *a = @[st1, st2, st3];
SKTexture *Texture = [SKTexture textureWithImageNamed: a[arc4random_uniform(a.count)]];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top