Last active
May 8, 2022 14:37
-
-
Save bsorrentino/64a35b6c70f64ebc2ff5b405b2fb33c8 to your computer and use it in GitHub Desktop.
Swift Utilities for Xcode
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
// | |
// App+Version.swift | |
// | |
// Created by bsorrentino on 29/12/2019. | |
// Copyright © 2019 Bartolomeo Sorrentino. All rights reserved. | |
// | |
import Foundation | |
// | |
// @see https://www.hackingwithswift.com/example-code/system/how-to-read-your-apps-version-from-your-infoplist-file | |
// | |
public func appVersion() -> String { | |
if let result = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String { | |
if let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String { | |
return "\(result) (\(build))" | |
} | |
return result | |
} | |
return "no version" | |
} | |
public func appName() -> String { | |
if let result = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String { | |
return result | |
} | |
return "KeyChainX" | |
} |
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
// | |
// XCode+Utils.swift | |
// slides | |
// | |
// Created by bsorrentino on 05/07/21. | |
// Copyright © 2021 bsorrentino. All rights reserved. | |
// | |
import Foundation | |
// for SwiftUI development | |
// detect if the view is rendered in preview | |
var isInPreviewMode:Bool { | |
(ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] != nil) | |
} | |
// for Swift development | |
// detect if the code is running on Simulator | |
#if targetEnvironment(simulator) | |
// Simulator! | |
let isRunningOnSimulator = true | |
#else | |
let isRunningOnSimulator = false | |
#endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment