Skip to content

Instantly share code, notes, and snippets.

@asaday
Created December 20, 2016 01:14
Show Gist options
  • Save asaday/90caee71d2bb191c608f5bd6d4670dae to your computer and use it in GitHub Desktop.
Save asaday/90caee71d2bb191c608f5bd6d4670dae to your computer and use it in GitHub Desktop.
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