Skip to content

Instantly share code, notes, and snippets.

View Deco354's full-sized avatar

Declan McKenna Deco354

View GitHub Profile
@Deco354
Deco354 / Architecture.swift
Created May 23, 2022 14:59
Simulator Architecture Detector
//
// Architecture.swift
// TumblrSnapshotTestCase
//
// Created by Declan McKenna on 26/01/2022.
//
import Foundation
@objc(PSTArchitecture) public final class Architecture: NSObject { // @arnold no-tests
@Deco354
Deco354 / shortcuts.md
Last active March 30, 2023 06:50
A list of Xcode development shortcuts

⌘ command + J - Choose Editor

- Open quick find result in secondary editor

+ + + - Focus Current Editor

+ + J - Jump to definition

+ + + H - Find Call Hierarchy

import UIKit
class ViewController{
var networking: NetworkManager? = NetworkManager() // Unlike storedHandler this doesn't cause a leak unless it stores the completion
var isLoading = false
func loadImages() {
networking?.downloadImages { isSuccess in
self.isLoading = isSuccess
print("Images download completed")
@Deco354
Deco354 / Retain Cycle
Created July 9, 2020 16:16
Example showing a retain cycle only if the completionHandler of an object is explicitly stored
import UIKit
class ViewController{
var networking: NetworkManager? = NetworkManager() // Unlike storedHandler this doesn't cause a leak unless it stores the completion
var isLoading = false
func loadImages() {
networking?.downloadImages { isSuccess in
self.isLoading = isSuccess
print("Images download completed")
@Deco354
Deco354 / URLSessionRetainCycle.swift
Created July 9, 2020 15:13
URLSession Lack of Retain Cycle Example
import Foundation
class ViewController{
var networking = URLSession.shared
var isLoading = false
func loadImages() {
print("loading images")
networking.dataTask(with: URL(string: "https://deckofcardsapi.com/api/deck/new/draw/?count=52")!) { (_, _, _) in
print("Load Complete")
protocol DualTextFieldViewModel {
var field1Hint: String { get }
var field2Hint: String { get }
}
struct NinjaViewModel: DualTextFieldViewModel {
let field1Hint = "Leaf"
let field2Hint = "Nine tail fox"
}
@Deco354
Deco354 / Imagen
Created November 3, 2019 16:14
Uploads image to TinyPNG API via Swift and prints location
//
// File.swift
//
//
// Created by Declan on 02/11/2019.
//
import Foundation
public final class Imagen {