如何在XCODE中创建学生姓名数组

时间:2017-11-21 01:30:53

标签: objective-c xcode

NSArray *student = [NSArray arrayWithObjects:@"peter", @"Daniel", @"Mary", @"Yanah", @"Raju", @"Sue" count:<#(NSUInteger)#>]

在&#34;苏&#34;?

之后我会写什么?

3 个答案:

答案 0 :(得分:1)

NSArray *student = [NSArray arrayWithObjects:@"peter", @"Daniel", @"Mary", @"Yanah", @"Raju", @"Sue", nil];

答案 1 :(得分:1)

您使用的API不合适,因为objects必须是C数组,例如

NSString *names[3];
names[0] = @"peter";
names[1] = @"Daniel";
names[2] = @"Mary";

NSArray *students = [NSArray arrayWithObjects: names count:3];

在您的情况下,强烈建议您使用现代文字语法:

NSArray *students = @[@"peter", @"Daniel", @"Mary", @"Yanah", @"Raju", @"Sue"];

答案 2 :(得分:0)

您可以通过以下方式轻松完成

第1步:

NSArray *student = [[NSArray alloc] initWithObjects:@"peter", @"Daniel", @"Mary", @"Yanah", @"Raju", @"Sue", nil];

第2步:

NSArray *student = [NSArray arrayWithObjects:@"peter", @"Daniel", @"Mary", @"Yanah", @"Raju", @"Sue", nil];

第3步:

NSArray *student = @[@"peter", @"Daniel", @"Mary", @"Yanah", @"Raju", @"Sue"];