如何创建NSMutableArray并为其分配特定对象? [英] How to create an NSMutableArray and assign a specific object to it?
问题描述
我刚进入Obj C,我正在寻找创建一个MKAnnotations数组。
I am just getting into Obj C, and I am looking to create an array of MKAnnotations.
我已经创建了名为 TruckLocation
的MKAnnotation类,其中包含名称,描述,纬度和经度。
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];
推荐答案
Yore尝试将2种不同的语法组合成相似但不同的的东西。您似乎也没有任何注释实例。
Yore trying to combine 2 different syntaxes for similar but different things. You also don't seem to have any instances of your annotations.
创建一些实例
TruckLocation *a1 = ...;
TruckLocation *a2 = ...;
然后我们可以添加它们
NSMutableArray *trucksArray = [NSMutableArray arrayWithObjects:a1, a2, nil];
或
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.
这篇关于如何创建NSMutableArray并为其分配特定对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!