Skip to content

Instantly share code, notes, and snippets.

View mannd's full-sized avatar
🏠
Working from home

David Mann mannd

🏠
Working from home
View GitHub Profile
@mannd
mannd / gist:d5188991deaae17f330af8877e5f68e1
Created September 7, 2018 01:33
iOS getVersion() Swift
func getVersion() -> String {
// if this doesn't unwrap, something is really wrong
guard let dictionary = Bundle.main.infoDictionary else {
preconditionFailure("Error: main bundle not found!")
}
let version = dictionary["CFBundleShortVersionString"] ?? "error"
#if DEBUG // Get build number, if you want it. Cleaner to leave out of release version.
let build = dictionary["CFBundleVersion"] ?? "error"
// the version+build format is recommended by https://semver.org
let versionBuild = "\(version)+\(build)"
@mannd
mannd / gist:e5a17d6f89a6baa68d610d90bd2f198e
Created September 7, 2018 00:36
get iOS version string using objective C
- (NSString *)getVersion {
NSDictionary *dictionary = [[NSBundle mainBundle] infoDictionary];
NSString *version = dictionary[@"CFBundleShortVersionString"];
#ifdef DEBUG // Get build number, if you want it. Cleaner to leave out of release version.
NSString *build = dictionary[@"CFBundleVersion"];
// the version+build format is recommended by https://semver.org
NSString *versionBuild = [NSString stringWithFormat:@"%@+%@", version, build];
return versionBuild;
#else
return version;