Ste*_*eve 1 arrays iphone floating-point boolean objective-c
NSArray chemConstantArray = [[NSArray alloc] initWithObjects:0.0021400, 0.0012840, 0.0010700, nil];
Run Code Online (Sandbox Code Playgroud)
给我四个错误:
Incompatible type for argument 1 of 'initWithObjects:'
Invalid initializer
Statically allocated instance of Objective-C class 'NSArray' x 2
这是有道理的,因为浮点数不是对象,但我如何制作浮点数组.我也需要BOOL一个.
如果您需要一个纯粹在您自己的代码中的数组,您可以使用常规C数组:
float chemConstantArray[] = {0.0021400, 0.0012840, 0.0010700};
Run Code Online (Sandbox Code Playgroud)
如果你需要一个NSArray*东西,你需要将每个值包装成一个NSNumber.
NSArray *chemConstantArray = [[NSArray alloc] initWithObjects:
[NSNumber numberWithFloat: 0.0021400],
[NSNumber numberWithFloat: 0.0012840],
[NSNumber numberWithFloat: 0.0010700],
nil];
Run Code Online (Sandbox Code Playgroud)
您可以numberWithBool类似地使用BOOL.
| 归档时间: |
|
| 查看次数: |
3569 次 |
| 最近记录: |