ios - Default value for a List in Realm -


i have realm model class below.

class trip: object {     dynamic var userid: string = ""     dynamic var id: int = 0     dynamic var starttimestamp: int64 = 0     dynamic var endtimestamp: int64 = 0     let bumplocations = list<bumplocation>()     let brakelocations = list<brakelocation>()     dynamic var distance: double = 0.0     dynamic var calories: double = 0.0     dynamic var averagespeed: double = 0.0 } 

i create objects of this.

let tripdata: [string: any] = [     "userid": self.trip!.userid,     "id": self.trip!.id,     "starttimestamp": self.trip!.starttimestamp,     "endtimestamp": self.trip!.endtimestamp,     "distance": self.trip!.distance,     "calories": self.trip!.calories,     "averagespeed": self.trip!.averagespeed ] realm.create(trip.self, value: tripdata, update: true) 

at time of creating these objects, there no values added properties bumplocations , brakelocations. need add default values these fields, right?

what's default value properties of type list?

i crash @ realm.create. think because create function expects properties of model class listed in dictionary same way specified in class. , since it's missing bumplocations , brakelocations, messes order class created value dictionary? in adds value of distance field bumplocations property , calories value brakelocations property , on.

the crash reports got.

report #1

report 2

got output in debug console.

no, don't need add default values 2 lists, since have default value of empty list defined in realm object class definition.

in line let bumplocations = list<bumplocation>() parentheses create shorthand notation calling init method without input arguments, line assigns empty list bumplocations variable.

class trip: object {     ...     let bumplocations = list<bumplocation>()     let brakelocations = list<brakelocation>() } 

below code valid.

let tripdata: [string: any] = [     "userid": self.trip!.userid,     "id": self.trip!.id,     "starttimestamp": self.trip!.starttimestamp,     "endtimestamp": self.trip!.endtimestamp,     "distance": self.trip!.distance,     "calories": self.trip!.calories,     "averagespeed": self.trip!.averagespeed, ] try! realm.write {     realm.create(trip.self, value: tripdata) } 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -