How to use
Dictionary.compactMapValues
potatotips #55
Daiki Matsudate / @d_date
Slide 2
Slide 2 text
Daiki Matsudate
@d_date
Slide 3
Slide 3 text
https://peaks.cc/iOS_architecture
Slide 4
Slide 4 text
IUUQTZBLJSJOHPCPPUIQNJUFNT
Slide 5
Slide 5 text
Dictionary
.compactMapValues
Slide 6
Slide 6 text
extension Dictionary {
public func compactMapValues(_ transform: (Value) throws -> T?) rethrows -> [Key: T]
{
return try self.reduce(into: [Key: T](), { (result, x) in
if let value = try transform(x.value) {
result[x.key] = value
}
})
}
}
Available in Swift 5