【发布时间】:2017-10-08 04:08:09
【问题描述】:
我想把这条 swift 行转换成 Objective-C
let location = CLLocationCoordinate2D(latitude: (marker.userData as! location).lat, longitude: (marker.userData as! location).lon)
userData 的 id 类型被强制向下转换为 location 但是当我尝试在 Objective-C 中转换 userData 时,我得到了这个:
发现多个名为“location”的方法结果不匹配, 参数类型或属性
这是我的代码:
struct CLLocationCoordinate2D markerLocation;
markerLocation.longitude=[(CLLocation *)[marker.userData location] coordinate].longitude;
【问题讨论】:
-
在 Objective-C 代码中,您在 userData 上调用方法“位置”。您只需要将 userData 类型转换为您的预期类型。 BTW userData 的类型是什么?
-
UserData 的类型为“id”。由于 location 是指向 CLLocation 的指针,我已将其转换为 CLLocaton 但它不起作用。我想以任何方式将那条快速线转换为Objective-C。你有什么建议吗?
标签: objective-c swift struct