[swift-users] Making functions generic on optionals

Brent Royal-Gordon brent at architechies.com
Fri Feb 5 16:41:22 CST 2016


>     public class func sortDescriptorsFromString(sortString :String?) throws -> [NSSortDescriptor]? {
>         guard let sortString = sortString else {return nil}
>         return try self.sortDescriptorsFromString(sortString)
>     }
> 
> }

This is equivalent to (something like):

	return try sortString.map(self.sortDescriptorsFromString)

You can always use that directly at the call sites where you have an optional String.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-users mailing list