Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let compatiblePreferences = rawValues.filter { defaults[$0.key] != nil }
- rawValues = defaults.merging(compatiblePreferences) { (_, new) in new }
- // My understanding is that Swift lambdas can have anonymous parameters:
- rawValues.filter { // no named lambda parameter here
- defaults[$0.key] != nil
- }
- // or named parameters
- rawValues.filter { value in // `$0` is named value and `in` is used to finish statement
- defaults[value.key] != nil
- }
- // That helps us understand the second line:
- defaults.merging(compatiblePreferences) { (_, new) in new }
- // It can be reformatted as:
- defaults.merging(compatiblePreferences) { (_, new) in // 2 names parameters for the conflicting values of both lists; note that `_` tells Swift to ignore the first parameter; we don't need it so we don't name it
- new // implicit `return` of new -> we always pick new value on conflicting key
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement