This file contains 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
extension Optional where Wrapped == String { | |
func orEmpty() -> String { | |
return self ?? "" | |
} | |
} |
This file contains 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
extension UIView { | |
// MARK: - Safe anchors | |
/// Contains view's top anchor depending to iOS version. | |
var safeTopAnchor: NSLayoutYAxisAnchor { | |
if #available(iOS 11.0, *) { | |
return self.safeAreaLayoutGuide.topAnchor | |
} else { | |
return self.topAnchor |
This file contains 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
//Declare extension to URLRequest: | |
extension URLRequest { | |
public var curlString: String { | |
// Logging URL requests in whole may expose sensitive data, | |
// or open up possibility for getting access to your user data, | |
// so make sure to disable this feature for production builds! | |
#if !DEBUG | |
return "" |
This file contains 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
static func systemUptime() -> TimeInterval { | |
var currentTime = time_t() | |
var bootTime = timeval() | |
var mib = [CTL_KERN, KERN_BOOTTIME] | |
// NOTE: Use strideof(), NOT sizeof() to account for data structure | |
// alignment (padding) | |
// http://stackoverflow.com/a/27640066 | |
// https://devforums.apple.com/message/1086617#1086617 | |
var size = MemoryLayout<timeval>.stride | |
let result = sysctl(&mib, u_int(mib.count), &bootTime, &size, nil, 0) |