I have an NSDictionary
that contains keys and values, and some values will also be NSDictionary
s... to an arbitrary (but reasonable) level.
I would like to get a list of all valid KVC paths, e.g. given:
{
"foo" = "bar",
"qux" = {
"taco" = "delicious",
"burrito" = "also delicious",
}
}
I would get:
[
"foo",
"qux",
"qux.taco",
"qux.burrito"
]
Is there a simple way to do this that already exists?
Here is a Swift version I wrote after taking note from Matt's answer.
You could recurse through
allKeys
. A key is a key path, obviously, and then if the value is an NSDictionary you can recurse and append.And here is how to call it:
Afterwards,
arr
contains your list of key paths.