[ad_1]
I’ve a reasonably easy for-loop that I wish to refactor to be extra “Swifty”. I am positive that is do-able with some form of map or different cool mechanism. If it isn’t an excessive amount of to ask, it will be helpful of me to listen to a thought-process behind refactoring/creating these, because it’s one space of Swift that I simply can’t appear to wrap my head round very effectively (I am caught on an old-school for-loop mindset!).
The loop goes via an array of dictionaries to search out the one we want (primarily based on a refKey==refVal), then it merely pulls a distinct worth wanted from that specific dictionary primarily based on “keyForWhatWeWant”:
for currentDictionary in dictionaries the place currentDictionary["refKey"] == "refVal" {
if let valueWeWant = currentDictionary["keyForWhatWeWant"] {
return valueWeWant
}
}
I do need it to go via this code and transfer on if it doesn’t discover the worth, although, FYI.
[ad_2]
