view LazyBear/Global functions/UnwrapAnyOptional.swift @ 450:4b8031e696e8

Change Bazooka to Alamofire Alamofire is compatible with WatchOS and MacOS
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sat, 26 Jun 2021 16:36:53 +0200
parents f71761f166f2
children
line wrap: on
line source

//
//  UnwrapAnyOptional.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 23/6/21.
//

import SwiftUI

/*
 Unwrap optional Int, Double, String into String
 */
func unwrapAnyOptional(value: Any) -> String? {
    if let value = value as? Int {
        return "\(value)"
    } else if let value = value as? Double {
        return String(format: "%.3f", value)
    } else {
        return value as? String
    }
}