This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension String { | |
| var isAlphanumeric: Bool { | |
| !isEmpty && range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| extension UIImage { | |
| var squared: UIImage? { | |
| let originalWidth = size.width | |
| let originalHeight = size.height | |
| var x: CGFloat = 0.0 | |
| var y: CGFloat = 0.0 | |
| var edge: CGFloat = 0.0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| extension UIImage { | |
| func resized(maxSize: CGFloat) -> UIImage? { | |
| let scale: CGFloat | |
| if size.width > size.height { | |
| scale = maxSize / size.width | |
| } | |
| else { | |
| scale = maxSize / size.height |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension Int { | |
| func toString() -> String { | |
| "\(self)" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension Double { | |
| func toString() -> String { | |
| String(format: "%.02f", self) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension Double { | |
| func toPrice(currency: String) -> String { | |
| let nf = NumberFormatter() | |
| nf.decimalSeparator = "," | |
| nf.groupingSeparator = "." | |
| nf.groupingSize = 3 | |
| nf.usesGroupingSeparator = true | |
| nf.minimumFractionDigits = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension String { | |
| var asDict: [String: Any]? { | |
| guard let data = self.data(using: .utf8) else { return nil } | |
| return try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension String { | |
| var asArray: [Any]? { | |
| guard let data = self.data(using: .utf8) else { return nil } | |
| return try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [Any] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension String { | |
| var asAttributedString: NSAttributedString? { | |
| guard let data = self.data(using: .utf8) else { return nil } | |
| return try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension Bundle { | |
| var appVersion: String? { | |
| self.infoDictionary?["CFBundleShortVersionString"] as? String | |
| } | |
| static var mainAppVersion: String? { | |
| Bundle.main.appVersion | |
| } |