Adding Realm Lists to an updated App

Hey All,

I will try over here and see if you all have any ideas.

I have an app in the app store that I am waiting to submit until I figure how to protect the user’s data they have already placed in the database

Here is the current Model:

Here are my models The first is the original:

class Registry: Object {

//Date, time, place and type
@objc dynamic var registryId = UUID().uuidString

@objc dynamic var dateTime:String?
@objc dynamic var proper:String?
@objc dynamic var service:String?
@objc dynamic var place:String?

//Attendance
//Sunday
@objc dynamic var sunEuchAttendance:Int = 0

//All Other services
@objc dynamic var otherServiceAttendance:Int = 0
@objc dynamic var EuchVisitor:Int = 0

//Commuion
@objc dynamic var numberOfCommunions:Int = 0

//People serving
@objc dynamic var presiderOfficiant:String?
@objc dynamic var preacher:String?
@objc dynamic var server:String?
@objc dynamic var memo:String?

//Stats
//Eucharist
@objc dynamic var weekendEuch:Int = 0
@objc dynamic var weekdayEuch:Int = 0
@objc dynamic var privateEuch:Int = 0

//Office
@objc dynamic var weekendOffice:Int = 0
@objc dynamic var weekdayOffice:Int = 0

//Other services
@objc dynamic var burrial:Int = 0
@objc dynamic var marraige:Int = 0

//Other services and memos
@objc dynamic var other:Int = 0

override static func primaryKey() -> String? {
return “registryId”
}

override static func indexedProperties() -> [String] {
return [“service”]
}
}

And when I update the app to include lists I need to migrate exiesting data into the new list:

class AllServices: Object {

var everything = List()
var eucharist = List()
var weekdayEucharist = List()
var office = List()
var weekdayOffice = List()
var marriage = List()
var burial = List()
var requiem = List()
var nuptial = List()
var other = List()
}

I was told to do this:

Here is how you should do:
1.) create a new list, with the type of property “var newList = List()”
2.) iterate over all of the old data and create a Registry from each of them “let newData = Registry.init(…)”
3.) add those data to the newList “newList.add(newData)”
4.) set the newData new property to the newList “newObject[“listProperty”] = newList”

But for the life of me, I can’t figure out how to execute the instructions. When I try them, I get s serries of errors.

Thanks so much for the help!

Blessings,
—Mark

why was the value set as List()?

anyway i think you need to know more details regarding the errors and the code how you executed this

Hey Francis,

Chris was instrumental in getting me unstuck with this problem. The Realm gurus in their forum were advising that I needed to update the lists in a migration block. Nope, that did not work. Instead, I already had initializing code that ran each time, I just looped through all the Registry objects and utilized a method I already had to save them to the Lists. So simple once I got unstuck!

Each List is a list of Registry objects that display the category. Since the typical user of the app will have a couple hundred Registry objects, being able to display just the group they were looking for with out having to duplicate that object is just what was needed. Hence a List.

Thanks.
Blessings,
—Mark