gpt4 book ai didi

objective-c - 将 swift 的 "forced downcast(as!)"转换为 objective-c

转载 作者:行者123 更新时间:2023-11-28 12:15:52 25 4
gpt4 key购买 nike

我想将这条 swift 代码转换为 Objective-C

let location = CLLocationCoordinate2D(latitude: (marker.userData as! location).lat, longitude: (marker.userData as! location).lon)

userData 是 id 类型,它被强制向下转换为 location 但是当我尝试在 Objective-C 中转换 userData 时,我得到这个:

Multiple methods named 'location' found with mismatched result, parameter type or attributes

这是我的代码:

struct CLLocationCoordinate2D markerLocation;
markerLocation.longitude=[(CLLocation *)[marker.userData location] coordinate].longitude;

最佳答案

你想转换 userData,而不是 location 消息的结果。

markerLocation.longitude=[(CLLocation *)[marker.userData location] coordinate].longitude;

……应该是……

markerLocation.longitude=[(CLLocation *)(marker.userData) coordinate].longitude;

关于objective-c - 将 swift 的 "forced downcast(as!)"转换为 objective-c ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46627406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com