Skip to content

Instantly share code, notes, and snippets.

Avatar

Declan McKenna Deco354

View GitHub Profile
@Deco354
Deco354 / shortcuts.md
Created Jul 15, 2020
A list of Xcode development shortcuts
View shortcuts.md

⌘ command + J - Choose Editor

- Open quick find result in secondary editor

+ + + - Focus Current Editor

+ + J - Jump to definition

+ + + H - Find Call Hierarchy

View RetainCycle.swift
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 Jul 9, 2020
Example showing a retain cycle only if the completionHandler of an object is explicitly stored
View Retain Cycle
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 Jul 9, 2020
URLSession Lack of Retain Cycle Example
View URLSessionRetainCycle.swift
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")
View Pirate.swift
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 Nov 3, 2019
Uploads image to TinyPNG API via Swift and prints location
View Imagen
//
// File.swift
//
//
// Created by Declan on 02/11/2019.
//
import Foundation
public final class Imagen {
You can’t perform that action at this time.