priore

replace "??" with function to shorten compilation time

Jul 23rd, 2019
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×