Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // replace "??" with static function to shorten compilation times
- //
- // Any
- public func ifn(_ value: Any?, _ default: String = String.empty) -> String {
- return value != nil ? "\(value!)" : `default`
- }
- // Generics
- public func ifn<T>(_ value: T?, _ default: T) -> T {
- return value ?? `default`
- }
- public func ifn<T>(_ condition: Bool?, _ trueResult: T?, _ falseResult: T?) -> T? {
- return (condition ?? false) ? trueResult : falseResult
- }
- public func ifn(_ condition: Bool?) -> Bool {
- return (condition ?? false) ? true : false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement