我在Xcode中有奇怪的错误,说我无法转换Size3D类型的值?除了Size3D类型的例外参数?我只在一个地方定义了Size3D - 不同的模块,但它已导入,我可以初始化Size3D。 错误出现在此代码的最后一行:
let size3D: Size3D? = {
guard let viewport = geometry["viewport"] as? [String : [String : Double]] else { return nil }
guard let northeast = viewport["northeast"], let southwest = viewport["southwest"] else { return nil }
guard let northeastLat = northeast["lat"], let northeastLng = northeast["lng"] else { return nil }
guard let southwestLat = southwest["lat"], let southwestLng = southwest["lng"] else { return nil }
let northeastECEF = ECEF(location: CLLocation(latitude: northeastLat, longitude: northeastLng))
let southwestECEF = ECEF(location: CLLocation(latitude: southwestLat, longitude: southwestLng))
let width = abs(southwestECEF.x - northeastECEF.x)
let depth = abs(southwestECEF.y - northeastECEF.y)
let size3D = Size3D(width: width, depth: depth, height: 3)
// If size is too large return nil.
return size3D.diagonal < 25 ? size3D : nil
}()
WorldObjectLocation(location: CLLocation(latitude: lat, longitude: lon), size3D: size3D, ignoreAltitude: true, ignoreCourse: true)
在此类中定义:
public class WorldObjectLocation: CLLocation {
public let ignoreLocationAltitude: Bool
public let ignoreLocationCourse: Bool
public let size3D: Size3D?
public init(location: CLLocation, size3D: Size3D?, ignoreAltitude: Bool, ignoreCourse: Bool) {
self.size3D = size3D
ignoreLocationAltitude = ignoreAltitude
ignoreLocationCourse = ignoreCourse
super.init(coordinate: location.coordinate, altitude: location.altitude, horizontalAccuracy: location.horizontalAccuracy, verticalAccuracy: location.verticalAccuracy, course: location.course, speed: location.speed, timestamp: location.timestamp)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
这里是Size3D:
public struct Size3D {
public let width: Double
public let depth: Double
public let height: Double
public init(width: Double, depth: Double, height: Double) {
self.width = width
self.depth = depth
self.height = height
}
public var diagonal: Double { return sqrt(width * width + depth * depth + height * height) }
}
这个错误是什么?如何解决这个问题?