Skip to content

Instantly share code, notes, and snippets.

View aoverholtzer's full-sized avatar

aoverholtzer

View GitHub Profile
@aoverholtzer
aoverholtzer / UIApplication+Hacks.swift
Created April 16, 2023 21:26
UIApplication and its methods are not available in iOS extensions, such as Share Extensions or Custom Keyboards. However, you can hack your way to, say, openURL if you really need to…
import UIKit
extension UIApplication {
public static func hacked_sharedApplication() -> UIApplication {
let selector = NSSelectorFromString("sharedApplication")
guard UIApplication.responds(to: selector) else {
fatalError("UIApplication.sharedApplication(): `UIApplication` does not respond to selector `sharedApplication`.")
}