假設我有很多城市對象。所以,城市ID將作爲我的主鍵,因爲它們不能重複。將會有相同的城市名稱,但不同的ID和不同的ShopAddress.Here是我的從JSON結果這是從我的後端RealmSwift數據過濾
{
"CityName" : "NewYork",
"ID" : 65,
"CityCode" : "NY",
"ShopAddress" : "NO.7\/8 17th quarter, 27th Street, LiverPool Township, NewYork."
},
{
"CityName" : "NewYork",
"ID" : 89,
"CityCode" : "NY",
"ShopAddress" : "NO.7\/8 17th quarter, 40th Street, West Stadium, NewYork."
},
{
"CityName" : "Maimi",
"ID" : 150,
"CityCode" : "MI",
"ShopAddress" : "NO.7\/8 17th quarter, 40th Street, West Stadium, Maimi."
}...etc
這裏是我的境界對象
import Foundation
import RealmSwift
class StoreList: Object {
dynamic var storeID : String = ""
dynamic var cityCode : String = ""
dynamic var cityName : String = ""
dynamic var shopAddress :String = ""
override static func primaryKey() -> String? {
return "storeID"
}
}
如何獲得其關注每個CityNames CityNames和適當的店鋪地址的數據?
for (var i = 0; i <= cityname.count; i++) {
cityItems.append("City Names from realm")
actualPositions.append(-1)
var items = [String]()
for (var i = 0; i < cityName["Newyork"].shopaddress.count; i++) {
items.append("the locations shop address of each item from each cities")
}
self.locationItems.append(items)
}
上面的代碼我寫的只是一個例子。會有很多錯誤。但是,我真的需要幫助filtering.Any幫助嗎?
我沒有得到你想要達到的目標嗎? – Anokrize
你看過我的屏幕截圖了嗎?這就是我想要做的。但是,我需要首先獲取數據保存到領域數據庫。將會有許多城市。每個城市將包括商店address.Cities可能是重複的,但城市id不會重複。 –
啊,所以你想顯示你的城市下的商店(如果有一些可用於城市)? – Anokrize