Skip to content

Instantly share code, notes, and snippets.

View grago's full-sized avatar

Gustavo Rago grago

View GitHub Profile
@grago
grago / extension.swift
Created December 14, 2018 06:32
[Extension - Decoding JSON from your bundle] #ios #swift
extension Bundle {
func decode<T: Decodable>(_ type: T.Type, from filename: String) -> T {
guard let json = url(forResource: filename, withExtension: nil) else {
fatalError("Failed to locate \(filename) in app bundle.")
}
guard let jsonData = try? Data(contentsOf: json) else {
fatalError("Failed to load \(filename) from app bundle.")
}
@grago
grago / uiapplication.swift
Last active May 7, 2020 05:43
[Link to subscription and app settings] #ios
extension UIApplication {
class func openAppSettings() {
guard let url = URL(string: self.openSettingsURLString) else { return }
self.shared.open(url, options: [:], completionHandler: nil)
}
class func openSubscriptionManagement() {
guard let url = URL(string: "itms://apps.apple.com/account/subscriptions") else { return }
self.shared.open(url, options: [:], completionHandler: nil)
}