Is there something like NSMutableArray
that will take doubles directly without putting them inside the @""
?
You can only put objects into an NSMutableArray
. But you can wrap your doubles in NSNumber
like so:
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
[array addObject:[NSNumber numberWithDouble:0.12345]];
[array addObject:[NSNumber numberWithDouble:5.43210]];
You can only insert objects into an NSMutableArray. Luckily, there is a class, NSNumber, that is used to wrap Objective-C primitives as objects. You can use the doubleValue method to get your primitive value back.
For example:
NSMutableArray *numArray = [[NSMutableArray alloc]initWithObjects:[NSNumber numberWithDouble:1.1f], nil];
double num = [[numArray objectAtIndex:0]doubleValue];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With