12345678910111213141516171819202122232425262728293031323334353637383940 |
- //
- // BaiduToCityFactory.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/4/28.
- // Copyright © 2019 南鑫林. All rights reserved.
- //
- import UIKit
- import SwiftyJSON
- import RealmSwift
- class BaiduToCityFactory: NSObject {
- static let shared : BaiduToCityFactory = BaiduToCityFactory()
- override init() {
- super.init()
- }
- func setSaveBaiduToCity() {
- let jsonStr = String.jsonFileToJsonStr(resource: "baidu_cityid_rel", type: "json")
- for city in String.getArrayFromJSONString(jsonString: jsonStr) {
- let city = BaiduToCityModel(fromJson: JSON(city))
- city.save()
- }
- }
- func query(bjcityId:String = "") -> BaiduToCityModel{
- var baiduToCityModel = BaiduToCityModel()
- // 根据条件获取数据
- let citys = BaiduToCityModel.rows(filter: "bjcityId = \(bjcityId)")
- if !citys.isEmpty {
- // 遍历输出结果
- for city in citys {
- baiduToCityModel = city
- NXLLog("\(city.areaCode), \(city.areaName),\(city.bjcityId)")
- }
- }
- return baiduToCityModel
- }
-
- }
|