Skip to content

Instantly share code, notes, and snippets.

View adamzarn's full-sized avatar

Adam Zarn adamzarn

View GitHub Profile
@adamzarn
adamzarn / Endpoint.swift
Last active February 28, 2022 19:44
A template for an Endpoint enum that implements URLRequestConvertible
import Foundation
enum Endpoint: URLRequestConvertible {
case one
case two
case three
var baseUrl: String {
return "https://www.example.com"
}
extension FileManager {
static var documentsDirectory: URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
enum ObjectStorageError: Error {
case objectDoesNotExist
case objectHasWrongType
case couldNotEncodeObject
@adamzarn
adamzarn / ImageCache.swift
Last active February 13, 2022 19:31
A singleton for managing a cache of images identified by their url strings.
import UIKit
class ImageCache: NSCache<NSString, UIImage> {
static let shared = ImageCache()
subscript(key: String) -> UIImage? {
get {
return object(forKey: NSString(string: key))
}
set {
@adamzarn
adamzarn / UIWindow+Extension.swift
Last active June 8, 2022 18:15
UIWindow Extension
extension UIWindow {
func setRootViewController(_ viewController: UIViewController) {
DispatchQueue.main.async {
self.rootViewController = viewController
self.makeKeyAndVisible()
}
}
}
@adamzarn
adamzarn / URLRequestConvertible.swift
Last active January 24, 2022 23:22
A protocol to make constructing a URLRequest easier
import Foundation
protocol URLRequestConvertible {
var baseUrl: String { get }
var path: String? { get }
var httpMethod: String { get }
var httpBody: Data? { get }
var allHTTPHeaderFields: [String: String] { get }
var url: URL? { get }
var urlRequest: URLRequest? { get }
@adamzarn
adamzarn / UIViewController+Extension.swift
Last active January 9, 2022 19:57
UIViewController Extension
extension UIViewController {
func showViewController(withIdentifier identifier: String, storyboardName: String = "Main") {
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: identifier)
self.view.window?.setRootViewController(viewController)
}
}
}
@adamzarn
adamzarn / Keychain.swift
Last active April 9, 2022 18:42
A class that makes it easy to store and retrieve string values from the Keychain
import Foundation
/* Example Usage:
Get
----------------------------
let token = Keychain[.token]
Set
----------------------------
Keychain[.token] = value
@adamzarn
adamzarn / fastlane-resign
Created August 5, 2020 02:47
A fastlane resign wrapper
#!/bin/bash
# ipa -> "Path/to/app.ipa"
ipa=$1
# provisioning_profile -> "Path/to/profile.mobileprovision"
provisioning_profile=$2
# signing_identity -> Example: "iPhone Distribution: Team Name (ABCDEFGHIJK)"
signing_identity=$3
# bundle_id -> Example: "com.org.app"
bundle_id=$4
@adamzarn
adamzarn / add-swift-support
Last active November 30, 2023 20:17
A bash script to add the SwiftSupport folder to an .ipa to resolve the ITMS-90426: Invalid Swift Support error.
#!/bin/bash
# Usage:
# 1. Copy the script into a text editor and save it with no extension
# 2. Make it executable like so: chmod +x path/to/script
# 3. Run it from the Terminal in one of two ways:
# * path/to/script ipa_path="path/to/ipa" archive_path="path/to/xcarchive"
# * path/to/script ipa_path="path/to/ipa" toolchain_path="path/to/toolchain"