swift 本地数据保存
iOS开发——数据持久化&本地数据的存储(使用NSCoder将对象保存到.plist文件) – iCocos – 博客园
Swift – 本地数据的保存与加载(使用NSCoder将对象保存到.plist文件)
ios查看CoreData数据保存SQLite文件路径(swift版本)
swift local storage
swift SQlite3 coredata
Core Data: How to Preload Data and Use Existing SQLite Database
swift store data locally
swift core data library
Swift core data: how to store objects
pepibumur/SugarRecord: Data persistence management library written in Swift 2.0
JohnEstropia/CoreStore: Unleashing the real power of Core Data with the elegance and safety of Swift
Getting Started with Core Data Tutorial
swift SugarRecord 教程
Swift语言指南 – GCZtian的专栏 – 博客频道 – CSDN.NET
Realm is a mobile database: a replacement for SQLite & Core Data
Swift Docs – Realm is a mobile database: a replacement for SQLite & Core Data
GitHub 上面有哪些适合新手阅读和学习的关于 iOS 开发的开源项目? – 知乎
-》目前看起来,还是:
Swift Docs – Realm is a mobile database: a replacement for SQLite & Core Data
好用。
抽空去试试。
【后记】
后来别人写了realm相关代码,如下:
<code>import RealmSwift func getProvinceList(_ parentId:Int = RegionAllProvinceParentId){ // 获取默认的 Realm 数据库 let realm = try! Realm() let ducumentPath2 = NSHomeDirectory() + "/Documents" let url = URL(string: ducumentPath2) //try realm.writeCopyToURL(NSURL(string: ducumentPath2)!) let fileURL = url!.deletingLastPathComponent() .appendingPathComponent("default.realm") do { try realm.writeCopy(toFile: (fileURL as NSURL) as URL) } catch { //XCTFail("writeCopyToURL failed") } // 检索 Realm 数据库 let puppies = realm.objects(RegionItems).filter("pid == 1") if puppies.count != 31 { getUrlRespDataJson_async( .GET, url: ServerApi.getRegionList(gCurUserItem.id, parentId: parentId), respJsonHandler: getProvinceListHandlers) } else { for item in puppies { getCityList(item.id) } } } func getProvinceListHandlers(_ respDataJson:Alamofire.Result<JSON>, mergedAllPara:Dictionary<String, AnyObject>) { gLog.verbose("respDataJson.debugDescription=\(respDataJson.debugDescription)") switch respDataJson { case .success(let dataJson): print(dataJson) guard let dataJsonArr = dataJson.array else { gLog.error("get empty region province list") return } let realm = try! Realm() for eachRegionJson in dataJsonArr { gLog.verbose("eachRegionJson=\(eachRegionJson)") let curRegionItem = parseJsonToRegionItem(eachRegionJson) gLog.verbose("curRegionItem=\(curRegionItem)") let regionItems = RegionItems() regionItems.id = curRegionItem.id regionItems.code = "\(curRegionItem.code)" regionItems.name = curRegionItem.name regionItems.pid = curRegionItem.parentId // 检索 Realm 数据库 let puppies = realm.objects(RegionItems.self).filter("id == \(regionItems.id)") if puppies.count == 0 { try! realm.write { realm.add(regionItems) } } } let ducumentPath2 = NSHomeDirectory() + "/Documents" let url = URL(string: ducumentPath2) //try realm.writeCopyToURL(NSURL(string: ducumentPath2)!) let fileURL = url!.deletingLastPathComponent() .appendingPathComponent("default.realm") do { try realm.writeCopy(toFile: (fileURL as NSURL) as URL) } catch { //XCTFail("writeCopyToURL failed") } case .failure(let error): gLog.verbose("error=\(error)") } } </code>
供参考。
转载请注明:在路上 » 【已解决】swift 本地数据保存