且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Objective c中为iphone创建一个字符串数组

更新时间:2023-02-12 19:15:30

你想要一个包含九个字符串的数组吗?

  [NSArray arrayWithObjects:@1,@2 ,@3,4,5,6,7,8,9,nil] 


I'm trying to create an array of strings that can be randomized and limited to a certain x number of strings.

If the array could be randomized I could pick the first x strings and that would work fine.

I'm trying to use code like this currently

NSString *statements[9];
statements[0] = @"hello";

This seems to work but the array seems to be full of rubbish data.

Can someone help me in the right direction. (is the memory allocation being done in the wrong way?

Thanks

Do you want an array with nine strings in it?

[NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil]