Skip to content

Instantly share code, notes, and snippets.

@tkc tkc/RealmModelSample
Last active Aug 5, 2016

Embed
What would you like to do?
import Foundation
import UIKit
import RealmSwift
class LocateModel: Object {
dynamic var lat = 0.0
dynamic var long = 0.0
dynamic var unixTime = 0
dynamic var dateString = ""
dynamic var title = ""
dynamic var comment = ""
func convert(){
self.title="title convert";
self.comment="comment convert";
self.dateFormat()
}
func dateFormat(){
let date = NSDate(timeIntervalSinceNow: NSTimeInterval(NSTimeZone.systemTimeZone().secondsFromGMT))
let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy年MM月dd日 HH:mm:ss"
let formattedDate = formatter.stringFromDate(date)
self.dateString=formattedDate;
let dateUnix: NSTimeInterval? = date.timeIntervalSince1970
self.unixTime=Int(dateUnix!)
}
}
public class LocateModelWrap{
func store(locateModel:LocateModel){
let realm = try! Realm()
try! realm.write {
realm.add(locateModel)
}
}
func getList() -> [LocateModel] {
let realm: Realm = try! Realm()
let models = realm.objects(LocateModel).sorted("lat")
let result = models.map {$0}
return result
}
func count() ->Int {
let realm: Realm = try! Realm()
let mapModel = realm.objects(LocateModel)
let count = mapModel.count
return count
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.