Reputation: 103
currently im loading my sounds with
NSString * strName = [NSString stringWithFormat:@"soundpack%ld", (long) (value+1)];
to get a value for each sound.
now i want to pull it out of an array. looks like this:
NSMutableArray * sounds = [NSMutableArray arrayWithObjects: @"soundpack1", @"soundpack2", @"soundpack3", @"soundpack4", @"soundpack5", @"soundpack6", @"soundpack7", @"soundpack8", @"soundpack9", nil];
NSUInteger count = [sounds count];
for (NSUInteger i = 0; i < count; ++i) {
NSInteger nElements = count - i;
NSInteger n = arc4random_uniform((u_int32_t )nElements) + i;
[sounds exchangeObjectAtIndex:i withObjectAtIndex:n];
}
NSString * strName0 = [sounds objectAtIndex:1];
ok, now i have shuffled the sounds., now i want to initialize like before with an specific value.
something like:
NSString * strName = [sounds objectAtIndex:%ld, (long) (value+1)];
or
NSString * strName = [sounds objectAtIndex:@"%ld", (long) (value+1)];
didn't work. but i don't know, how to do it now...
Upvotes: 0
Views: 127
Reputation: 10317
Try to change this line
NSString * strName = [sounds objectAtIndex:@"%ld", (long) (value+1)];
to
NSString * strName = [sounds objectAtIndex:(long) (value+1)];
Upvotes: 1
Reputation: 5957
Why dont u use the same snippet after shuffling?
NSString * strName = [NSString stringWithFormat:@"soundpack%ld", (long) (value+1)];
Upvotes: 0