【问题标题】:Why is CLLocationManager class a part of MapKit?为什么 CLLocationManager 类是 MapKit 的一部分?
【发布时间】:2021-07-29 05:37:18
【问题描述】:

我只导入了 MapKit 和 UIKit。然后在我的代码中我使用了类 CLLocationManager

var locMgr  = CLLocationManager()

我的代码可以正常工作。

但是有些奇怪。 CLLocationManager 不是 MapKit 框架的一部分。 CLLocationManager 是 CoreLocation 框架的一部分。 但无论如何都没有错误。这不是结果。我不明白它是如何工作的。

【问题讨论】:

    标签: swift xcode frameworks mapkit cllocationmanager


    【解决方案1】:

    MapKit 的功能和 CoreLocation 提供的类型(如 CLLocationCoordinate2DCLLocationDegrees 等)依赖于 CoreLocation 框架。为此,它导入 CoreLocation。

    由于 MapKit 在其公共 API 中使用 CoreLocation 类型,它还必须重新导出 CoreLocation 本身的导入,即使您没有手动导入 CoreLocation 也可以使用它。

    【讨论】:

    • 我可以在 Xcode 文档中看到 MapKit 依赖于 CoreLocaion 框架吗?
    • @Eddi 不幸的是,文档并没有直接清楚地说明“框架 A 依赖于框架 B”。 About Location Services and Maps 文档一起讨论了它们,但不是那么明确。确定的真正方法是:1) MapKit API 直接引用 CoreLocation API,如果不导入它是不可能的,2) 如果您查看 MapKit 标头(例如MapKit/MKPlacemark.h),您将...
    • ...直接查看这些导入(例如#import <CoreLocation/CLLocation.h>)。
    猜你喜欢
    • 1970-01-01
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    相关资源
    最近更新 更多