powing
(Albert)
1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>winter</key>
<dict>
<key>parents</key>
<string>barbados</string>
<key>girlfriend</key>
<string>hawaii</string>
<key>friends</key>
<string>honolulu</string>
</dict>
</dict>
</plist>
enum Calendar: String, CaseIterable, Codable {
case spring
case summer
case fall
case winter
}
enum HolidayHome: String, CaseIterable, Codable {
case barbados
case hawaii
case honolulu
}
struct HolidayPlanner: Codable {
struct Season: Codable {
var spring: [Calendar.AllCases : String]
}
struct Destination: Codable {
var barbados: [HolidayHome.AllCases : String]
}
var spring: Season
var barbados: Destination
private enum CodingKeys : String, CodingKey {
case spring
case barbados
}
}
I wanted to model a plist that I dynamically create to better manage the data, but I can’t figure out how to serialize the data from the plist into struct?
The problem is that each nested level, not being static, prevents me from doing this. I tried hardcoding the first nested level “spring” with an aim to iterate over all of the possible cases in the enum, but it didn’t work, and I don’t know if this is the right approach?
eskimo
(Quinn “The Eskimo!”)
2
I can’t figure out how to serialize the data from the plist into
struct?
I’m struggling to understand your requirements here. The example property list you posted doesn’t seem to make any sense. For example, the parents key is set to barbados and the girlfriend key is set to hawaii. Is that the property list you’re trying to parse? Or is it an example of what happens when things go wrong? If it’s the latter, can you post of the former?
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple