Reputation: 203
I need a float type array; don't know the size of array initially. When I will get the value of size, I want to add some float values in it by a for loop. This array need to be global because I want to update it from another view controller class. How can I do this?
For this I declared a NSMutableArray type object and add float value by a for loop.
@property (nonatomic, strong) NSMutableArray *speedRate;
for (NSInteger i = 0; i < self.assetArray.count; i++){
[self.speedRate addObject:[NSNumber numberWithFloat:1.0f]];
}
NSLog(@"speedRate.count =%lu",(unsigned long)self.speedRate.count);
NSLog(@"value =%f",[[self.speedRate objectAtIndex:1]floatValue]);
But I got speedRate.count =0 and value =0.000 . I want speedRate.count will be same as self.assetArray.count and value =1.0 . How can I achieve this?
Upvotes: 0
Views: 81
Reputation: 17844
Your code never actually allocates the array. Add
self.speedRate = [[NSMutableArray alloc] init];
before the loop.
Upvotes: 1