Reputation: 693
In the below class Individual field values will be available at different times(Multiple Local Notification) through out any date. So I am planning to update the each Realm objects multiple times when Local notification is handled by user.
class DailyStatus:Object {
dynamic var date = ""
dynamic var statusMA = ""
dynamic var roundsChanted = 0
dynamic var statusDA = ""
dynamic var statusSB = ""
dynamic var bookReading = ""
var todayDate: String {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
return dateFormatter.stringFromDate(NSDate())
}
override class func primaryKey() -> String? {
return "date"
}
override init() {
super.init()
date = todayDate
}
}
Don't know how can I update individual var of Realm Object using the Primary key multiple times. Need help on Realm Queries.
Upvotes: 1
Views: 1354
Reputation: 1543
If your object has a primary key you can always retrieve it via that key and simply update the specific property. For example:
try! Realm().write {
var status = Realm().objectForPrimaryKey(aKey)
status.statusDA = "NEW TEXT"
}
Upvotes: 2