'CLLocationCoordinate2D' 与协议 'decodable'/'encodable' 的冗余一致性
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' 与协议 'Decodable'
的冗余一致性
指出 CLLocationCoordinate2D
已经符合同一代码行的协议。不过,构建依赖于所述框架的目标非常有效。您有什么解决办法吗?
最佳,
格鲁
您的扩展不需要成为测试目标的一部分。
您使用@testable
属性
将您的主要应用程序目标导入到单元测试中
import XCTest
@testable import MyProject
class MyProjectViewControllerTests: XCTestCase {}
这允许您使用项目中的 类、扩展等,而无需将它们添加到测试目标。
我正在编写一个使用 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' 与协议 'Decodable'
的冗余一致性指出 CLLocationCoordinate2D
已经符合同一代码行的协议。不过,构建依赖于所述框架的目标非常有效。您有什么解决办法吗?
最佳,
格鲁
您的扩展不需要成为测试目标的一部分。
您使用@testable
属性
import XCTest
@testable import MyProject
class MyProjectViewControllerTests: XCTestCase {}
这允许您使用项目中的 类、扩展等,而无需将它们添加到测试目标。