Skip to content

Instantly share code, notes, and snippets.

View drewster99's full-sized avatar

Andrew Benson drewster99

  • Nuclear Cyborg Corp
  • Minnesota USA
View GitHub Profile
@drewster99
drewster99 / userAgent.swift
Created May 20, 2021 17:00
Swift - Generates a suitable UserAgent string on iOS / macOS / tvOS
static let userAgent: String = {
let info = Bundle.main.infoDictionary
let executable = (info?[kCFBundleExecutableKey as String] as? String) ??
(ProcessInfo.processInfo.arguments.first?.split(separator: "/").last.map(String.init)) ??
"Unknown"
let bundle = info?[kCFBundleIdentifierKey as String] as? String ?? "Unknown"
let appVersion = info?["CFBundleShortVersionString"] as? String ?? "Unknown"
let appBuild = info?[kCFBundleVersionKey as String] as? String ?? "Unknown"
@drewster99
drewster99 / iosFrameworkVersions.swift
Created January 25, 2021 16:33
Swift iOS Xcode get and print all dynamic framework versions at runtime
// iosFrameworkVersions.swift
//
// Created by Andrew Benson (@DrewsterBenson) on 1/11/2021.
// Copyright (C) 2021 Andrew Benson.
// License: MIT (https://opensource.org/licenses/MIT)
//
// Stick in AppDelegate to dump all your (non-Apple) framework versions, like this:
//
// Framework versions:
// Alamofire -- 4.9.0(1)
@drewster99
drewster99 / AutoResizeViewControllerForKeyboard.swift
Last active January 25, 2021 16:44
Move views out of the way when keyboard appears, Swift 4.1, using Auto-Layout / Interface Builder / Storyboard
{
// Move views when keyboard appears/disappears
// Snipped from ViewController.swift
// This constraint should be tied to the top superview or safe area in Storybaord
@IBOutlet weak var closeButtonTopConstraint: NSLayoutConstraint!
private var topConstraintOriginalConstant: CGFloat?
private var topConstraintScrolledConstant: CGFloat = 0