Initialize NSArray with floats?

后端 未结 7 2111
你的背包
你的背包 2021-02-12 19:54

Is this a valid way to initalize an NSArray with float objects?

NSArray *fatArray = [NSArray arrayWithObjects:
                    [NSNumber numberWithFloat:6.9]         


        
7条回答
  •  执笔经年
    2021-02-12 20:44

    Another lazy option is to just use an array of NSStrings and then getting the type of value you are looking for directly from the string.

    Like so:

    NSArray *arrayOfNumbers = [NSArray arrayWithObjects:@"3.12",@"3.2", @"12", @"15", nil];
    float number = [[arrayOfNumbers objectAtIndex:0] floatValue];
    

提交回复
热议问题