[英]Firebase Swift: How do I create a new collection using the UID under my “users” collection?
[英]how to extract from collection properties and insert in into new collection model in swift
我有_userLocations:[CLLocation]
集合存儲用戶geoDatas,我想循環拋出_userLocations集合並提取時間戳記,緯度和經度屬性,並插入到稱為savedLocations:[Location]=[]
模型集合中。 for循環,我有此錯誤_userLocations
'類型'[Location]'的值沒有成員'時間戳'
有人能幫我嗎 ?
我的模特
class Location {
@NSManaged var latitude: NSNumber?
@NSManaged var longitude: NSNumber?
@NSManaged var timestamp: NSDate?
}
for location in _userLocations {
savedLocations.timestamp = location.timestamp
savedLocations.latitude = location.coordinate.latitude
savedLocations.longitude = location.coordinate.longitude
}
之所以出現錯誤Value of type '[Location]' has no member 'timestamp'
的原因是,因為您savedLocations
的[Location]
是[Location]
。 Array
沒有timestamp
屬性 。
您需要做的是創建一個新的Location
對象並將其插入保存的savedLocations
for location in _userLocations {
let newLocation = Location()
newLocation.timestamp = location.timestamp
newLocation.latitude = location.coordinate.latitude
newLocation.longitude = location.coordinate.longitude
savedLocations.append(newLocation)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.