【发布时间】:2012-07-27 03:13:10
【问题描述】:
我对 iOS 开发还很陌生。
我有一个 viewController,它包含一个作为自定义类对象的属性。我们将该自定义类称为 ClassA。 ClassA 的对象有一个属性,它是另一个自定义类的对象的 NSMutableArray,我们将称之为 ClassB。 ClassB 有一个属性,它也是 CLLocation 类型的对象的 NSMutableArray。
从 viewController 的一个方法内部,我需要创建一个 CLLocationCoordinate2D 结构的 C 数组(CLLocationCoordinate2D 是 CLLocation 的一个属性)。这些 CLLocationCoordinate2D 中的每一个都需要来自 ClassB 和 ClassA 中的所有对象所拥有的所有 CLLocation 对象。如果我理解我所做的,我相信我有一个 3-D 数组。
我一直纠结于如何组装这个结构数组。如果它只是一个数组,我会这样做:
NSUInteger numberOfSteps = [objectOfClassX count];
CLLocationCoordinate2D coordinates[numberOfSteps];
for (NSInteger index = 0; index < numberOfSteps; index++) {
CLLocation *location = [objectOfClassX objectAtIndex:index];
CLLocationCoordinate2D coordinate = location.coordinate;
coordinates[index] = coordinate;
}
但是,我正在努力获取第一个数组中的每个对象,然后是第二个数组中的每个对象,然后是 CLLocationCoordinate2D 中的语法。
【问题讨论】:
标签: objective-c ios multidimensional-array