Created
October 4, 2016 16:56
-
-
Save jpmcglone/f1c1e32023832254f5303b8fd46afc4b to your computer and use it in GitHub Desktop.
Swift 3 - Set if not nil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func setIfNotNil<T>(_ obj: inout T?, _ other: T?) { | |
guard other != nil else { return } | |
obj = other | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I prefer the other one, being idiomatic. But I rather not mutate.