无法将CLLocationDegrees的值转换为期望的参数shopProperties

时间:2017-08-08 01:08:41

标签: ios arrays swift firebase type-conversion

我有一个看起来像这样的属性:

class shopProperties: NSObject {
    var Latitude: CLLocationDegrees?
}

当我执行此代码时:

 databaseRef.observeSingleEvent(of: .value, with: { (snapshot) in
            for child in snapshot.children {
                let snap = child as! FIRDataSnapshot
                let dictionary = snap.value as! [String: AnyObject]
                let shopProper = shopProperties()

                var latitude = dictionary["Latitude"]
                var longtitude = dictionary["Longtitude"]

                shopProper.Latitude = latitude as! CLLocationDegrees
                print(shopProper.Latitude)
                self.shopProperty.append(shopProper.Latitude)
})

我在构建时的编译错误中遇到此错误:

无法将CLLocationDegrees的值转换为预期参数shopProperties

我的问题是我如何追加这个以便我可以在班上访问它?

1 个答案:

答案 0 :(得分:0)

您的.shopProperty实例变量的类型为[shopProperties] 数组shopProperties 。因此,您需要将shopProperties类型对象附加到数组中。但是你要附加其他类型的对象。

将此self.shopProperty.append(shopProper.Latitude)更改为

self.shopProperty.append(shopProper)

N.B。:在旁注中,以类名的大写字母和属性名称的小写字母开头。