繁体   English   中英

“ CLLocationCoordinate2D”与协议“可解码” /“可编码”的冗余一致性

[英]Redundant conformance of 'CLLocationCoordinate2D' to protocol 'decodable'/'encodable'

我正在写一个使用CoreLocation的互用框架。 不要问我为什么,但是我有要求使CLLocation编码。 所以我想出了一个结构

struct CLLocationEncodingStruct: Codable {
    let coordinate: CLLocationCoordinate2D
    let altitude: CLLocationDistance
    let horizontalAccuracy: CLLocationAccuracy
    let verticalAccuracy: CLLocationAccuracy
    let speed: CLLocationSpeed
    let course: CLLocationDirection
    let timestamp: Date

    public init(with location: CLLocation) {
        coordinate = location.coordinate
        altitude = location.altitude
        horizontalAccuracy = location.horizontalAccuracy
        verticalAccuracy = location.verticalAccuracy
        speed = location.speed
        course = location.course
        timestamp = location.timestamp
    }

    var location: CLLocation {
        return CLLocation(coordinate: coordinate, altitude: altitude, horizontalAccuracy: horizontalAccuracy, verticalAccuracy: verticalAccuracy, course: course, speed: speed, timestamp: timestamp)
    }
}

然后,我在CLLocation的扩展中遵循Codable 将数据放入该结构或从中拉出数据。 为了使此工作有效,我还必须使CLLocationCoordinate2D符合Codable 为此,我编写了以下非常复杂的扩展

extenstion CLLocationCoordinate2D: Codable {}

现在,我想为更改做正确的事情,所以我想开始编写单元测试。 问题是我对CLLocationCoordinate2D扩展需要成为两个目标的一部分:单元测试和框架本身。 不幸的是,这无法编译。 它失败了

Redundant conformance of 'CLLocationCoordinate2D' to protocol 'Encodable'

“ CLLocationCoordinate2D”与协议“可解码”的冗余一致性

指出CLLocationCoordinate2D已经符合同一代码行上的协议。 但是,建立依赖于所述框架的目标是完美的。 您是否有解决办法?

最好,

杰鲁

您的扩展程序不必成为测试目标的一部分。

您可以使用@testable属性将主应用程序目标导入单元测试中

import XCTest

@testable import MyProject

class MyProjectViewControllerTests: XCTestCase {}

这使您可以使用项目中的类,扩展等,而无需将其添加到测试目标中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM