Skip to content

Instantly share code, notes, and snippets.

@bsorrentino
Last active May 8, 2022 14:37
Show Gist options
  • Save bsorrentino/64a35b6c70f64ebc2ff5b405b2fb33c8 to your computer and use it in GitHub Desktop.
Save bsorrentino/64a35b6c70f64ebc2ff5b405b2fb33c8 to your computer and use it in GitHub Desktop.
Swift Utilities for Xcode

Swift Utilities

//
// 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"
}
//
// 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