문제

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.

도움이 되었습니까?

해결책

NSArray *a = @[st1, st2, st3];
SKTexture *Texture = [SKTexture textureWithImageNamed: a[arc4random_uniform(a.count)]];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top