Mercurial > public > lazybear
comparison LazyBear/Global functions/UnwrapAnyOptional.swift @ 448:f71761f166f2
Handle when data is empty
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Wed, 23 Jun 2021 11:47:14 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
447:8621ba6fd457 | 448:f71761f166f2 |
---|---|
1 // | |
2 // UnwrapAnyOptional.swift | |
3 // LazyBear | |
4 // | |
5 // Created by Dennis Concepción Martín on 23/6/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 /* | |
11 Unwrap optional Int, Double, String into String | |
12 */ | |
13 func unwrapAnyOptional(value: Any) -> String? { | |
14 if let value = value as? Int { | |
15 return "\(value)" | |
16 } else if let value = value as? Double { | |
17 return String(format: "%.3f", value) | |
18 } else { | |
19 return value as? String | |
20 } | |
21 } |