I want to add the [NSDecimalNumber numberWithInt:i]
to an array using for loop.
It is hardcoded :
NSArray *customTickLocations = [NSArray arrayWithObjects: [NSDecimalNumber numberWithInt:1],[NSDecimalNumber numberWithInt:2],[NSDecimalNumber numberWithInt:3],[NSDecimalNumber numberWithInt:4],[NSDecimalNumber numberWithInt:5],[NSDecimalNumber numberWithInt:6],[NSDecimalNumber numberWithInt:7],[NSDecimalNumber numberWithInt:8],[NSDecimalNumber numberWithInt:9],[NSDecimalNumber numberWithInt:10],[NSDecimalNumber numberWithInt:11],[NSDecimalNumber numberWithInt:12],nil];
I want like this, but I can add only one object here....
for (int i=0; i<totalImagesOnXaxis; i++) { customTickLocations = [NSArray arrayWithObject:[NSDecimalNumber numberWithInt:i]]; }
Please help me out of this, Thanks in Advance, Madan
The main difference is that NSArray is for an ordered collection and NSSet is for an unordered collection. There are several articles out there that talk about the difference in speed between the two, like this one. If you're iterating through an unordered collection, NSSet is great.
In Objective-C, the compiler generates code that makes an underlying call to the init(objects:count:) method. id objects[] = { someObject, @"Hello, World!", @42 }; NSUInteger count = sizeof(objects) / sizeof(id); NSArray *array = [NSArray arrayWithObjects:objects count:count];
The primary difference between NSArray and NSMutableArray is that a mutable array can be changed/modified after it has been allocated and initialized, whereas an immutable array, NSArray , cannot.
arrays can't contain nil.
NSArray is immutable. Use the mutable version, NSMutableArray.
NSMutableArray * customTickLocations = [NSMutableArray new]; for (int idx = 0; idx < 12; ++idx) { [customTickLocations addObject:[NSDecimalNumber numberWithInt:idx]]; } ...
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