I am just getting into Obj C, and I am looking to create an array of MKAnnotations.
I have already created the MKAnnotation class called TruckLocation
that contains the name, description, latitude, and longitude.
Here is what I have so far for the array:
NSMutableArray* trucksArray =[NSMutableArray arrayWithObjects: @[<#objects, ...#>] nil];
Creating NSArray Objects Using Array Literals In addition to the provided initializers, such as initWithObjects: , you can create an NSArray object using an array literal. In Objective-C, the compiler generates code that makes an underlying call to the init(objects:count:) method.
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.
The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray . NSMutableArray is “toll-free bridged” with its Core Foundation counterpart, CFMutableArray .
In general, the collection classes (for example, NSMutableArray , NSMutableDictionary ) are not thread-safe when mutations are concerned. That is, if one or more threads are changing the same array, problems can occur.
Yore trying to combine 2 different syntaxes for similar but different things. You also don't seem to have any instances of your annotations.
Create some instances
TruckLocation *a1 = ...;
TruckLocation *a2 = ...;
Then we can add them
NSMutableArray *trucksArray = [NSMutableArray arrayWithObjects:a1, a2, nil];
Or
NSMutableArray *trucksArray = [@[a1, a2] mutableCopy]
This is a shorter and more modern form but you need to make it mutable as it will create an immutable instance.
Well:
NSString *a = @"a";
NSMutableArray *array = [NSMutableArray arrayWithObjects:a,nil];
//or
NSMutableArray *array = [[NSMutableArray alloc]init]; //alloc
[array addObject:a];
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