【发布时间】:2018-10-06 05:17:42
【问题描述】:
我想知道是否可以使用标准 swift 4 从 firebase 的 JSON 响应中对 GeoPoint 进行编码和解码?
现在看来,GeoPoint 是不可编码的?
我收到以下错误
No 'decode' candidates produce the expected contextual result type 'GeoPoint'
在我的 Codable 类中
final class Data: Codable
{
var location:GeoPoint = GeoPoint(latitude:0,longitude:0)
private enum CodingKeys: String, CodingKey
{
case geoloc
}
init(from decoder: Decoder) throws
{
let values = try decoder.container(keyedBy: CodingKeys.self)
do
{
located = try values.decode(Location.self, forKey: .geoloc) //error here
}
catch
{
print("data has location in server response\n")
}
}
func encode(to encoder: Encoder) throws
{
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(location, forKey: .geoloc)
}
}
【问题讨论】:
标签: swift firebase firebase-realtime-database swift4 geopoints