Created
December 20, 2016 01:14
-
-
Save asaday/90caee71d2bb191c608f5bd6d4670dae to your computer and use it in GitHub Desktop.
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
public extension Bundle { | |
func infoStringForKey(_ key: String) -> String { | |
return object(forInfoDictionaryKey: key) as? String ?? "" | |
} | |
var version: String { return infoStringForKey("CFBundleShortVersionString") } | |
var build: String { return infoStringForKey("CFBundleVersion") } | |
var displayName: String { return infoStringForKey("CFBundleDisplayName") } | |
var identifier: String { return infoStringForKey("CFBundleIdentifier") } | |
} | |
public extension UIDevice { | |
var identifier: String { | |
var systemInfo = utsname() | |
uname(&systemInfo) | |
let mirror = Mirror(reflecting: systemInfo.machine) | |
let identifier = mirror.children.reduce("") { identifier, element in | |
guard let value = element.value as? Int8, value != 0 else { return identifier } | |
return identifier + String(UnicodeScalar(UInt8(value))) | |
} | |
return identifier // iPhone7,1 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment