Given this model:
public class RSS2Feed { public var channel: RSS2FeedChannel? public init() {} } public class RSS2FeedChannel { public var title: String? public var description: String? public init() {} }
What do I need to do to get the property names and values ββof the RSS2FeedChannel instance?
Here is what I am trying:
let feed = RSS2Feed() feed.channel = RSS2FeedChannel() feed.channel?.title = "The Channel Title" let mirror = Mirror(reflecting: feed.channel) mirror.children.first // ({Some "Some"}, {{Some "The Channel Title... for (index, value) in mirror.children.enumerate() { index // 0 value.label // "Some" value.value // RSS2FeedChannel }
Ultimately, I'm trying to create a Dictionary that matches the instance using reflection, but so far I canβt get the name of the property and the value of the instance.
The documentation states that:
If necessary, an optional label may be used, for example. to represent the name of the stored property or the active enumeration case and will be used to search when strings are passed to the child method.
But I only get the string "Some".
In addition, the value property returns a string of type RSS2FeedChannel when I expect each child to be a "Reflected Instance Structure Element."
source share