【问题标题】:How to use bridge for CLLocationCoordinate2D如何为 CLLocationCoordinate2D 使用桥接
【发布时间】:2013-03-01 10:27:06
【问题描述】:

AM 试图将 CLLocationCoordinate2D[] 添加到 NSMutableArray 并将其作为参数发送。但是 (__bridge id) 正在使应用程序崩溃。结构到 id 的转换是问题所在。任何人都可以请让我知道如何使用它。

CLLocationCoordinate2D 坐标[1000];

coordinates[index] --- 循环添加的所有坐标。

NSMutableArray *coorArray = [NSMutableArray array];
[coorArray addObject:(__bridge id)(coordinates)]; crashes here

【问题讨论】:

  • 如果我理解正确,你想创建一个 CLLocationCoordinate2D 的数组?

标签: objective-c struct cllocation bridge


【解决方案1】:

用途:

NSMutableArray *coorArray = [NSMutableArray array];
[coorArray addObject:[NSValue valueWithPointer:coordinates]];

那么当你要检索struct的数组时:

CLLocationCoordinate2D coordinates[] = [coorArray objectAtIndex:0].pointerValue;

C 数组不是对象,因此无法桥接。

【讨论】:

    【解决方案2】:

    您应该查看 +[NSValue valueWithBytes:objCType:] 而不是 (__bridge) 演员表。桥是用于其他用途的。

    例如: [NSValue value:&coordinate withObjCType:@encode(CLLocationCoordinate2D)];

    我想也可以对整个数组进行编码

    【讨论】:

    • 在这种情况下,坐标不是 CLLocationCoordinate2D 的数组。
    • 我接受了 Rikkles 的回答,因为这正是我想要的。我仍然应该给你一个UP,因为你努力帮助我。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 2012-01-06
    • 2015-08-18
    • 1970-01-01
    • 2012-12-28
    • 2012-04-29
    • 2011-02-27
    相关资源
    最近更新 更多