Advertisement
priore

replace "??" with function to shorten compilation time

Jul 23rd, 2019
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.55 KB | None | 0 0
  1. //
  2. // replace "??" with static function to shorten compilation times
  3. //
  4. // Any
  5. public func ifn(_ value: Any?, _ default: String = String.empty) -> String {
  6.     return value != nil ? "\(value!)" : `default`
  7. }
  8.  
  9. // Generics
  10. public func ifn<T>(_ value: T?, _ default: T) -> T {
  11.     return value ?? `default`
  12. }
  13.  
  14. public func ifn<T>(_ condition: Bool?, _ trueResult: T?, _ falseResult: T?) -> T? {
  15.     return (condition ?? false) ? trueResult : falseResult
  16. }
  17.  
  18. public func ifn(_ condition: Bool?) -> Bool {
  19.     return (condition ?? false) ? true : false
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement