假设我有很多城市对象。所以,城市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