我有一个uiview的子类,并且在其initWithFrame:
方法中我将nsarray转换为浮点数组,如下所示:
NSArray *numbersArray = @[[NSNumber numberWithFloat:0.2], [NSNumber numberWithFloat:.8], [NSNumber numberWithFloat:.3], [NSNumber numberWithFloat:.6], [NSNumber numberWithFloat:.2]];
data = malloc(numbersArray.count * sizeof(float));
if (data == NULL) {
// handle error
}
[numbersArray enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(NSNumber *number, NSUInteger idx, BOOL *stop) {
data[idx] = [number floatValue];
}];
//free(floatsArray);
for (int i = 0; i < sizeof (data) / sizeof (float); i++) {
NSLog(@"float value found at %i => %f", i, data[i]);
}
如果您自己运行代码,您将看到它只返回数组中的2个值。我在这里做错了什么?