Skip to content

Instantly share code, notes, and snippets.

@TheiOSDude
TheiOSDude / DIFactory
Created November 15, 2021 16:56
Swift DI with Factories
import UIKit
// Services conforming to protocols.
// SOLID: Depend on abstractions, not concrete implementations. Dependency Inversion principle
// DECLARE FIRST SERVICE
protocol MyFirstServiceProtocol {
func myFirstMethod()
}
@TheiOSDude
TheiOSDude / NameViewerFailure.swift
Created April 11, 2021 21:17
NameViewerFailure.swift
func test_failure() {
let response =
"""
[
{
"firstName": "Lee",
"lastName": "Burrows"
},
{
@TheiOSDude
TheiOSDude / NameViewerTests.swift
Created April 11, 2021 21:12
NameViewerTests
func test_success() {
let response =
"""
[
{
"firstName": "Lee",
"lastName": "Burrows"
},
{
@TheiOSDude
TheiOSDude / NameService.swift
Created April 11, 2021 20:49
NameService.swift
struct PersonName: Codable {
var firstName: String
var lastName: String
}
final class NameService {
private var apiClient: APIClientProtocol
init(apiClient: APIClientProtocol) {
self.apiClient = apiClient
@TheiOSDude
TheiOSDude / MockURLProtocol.swift
Created April 11, 2021 20:26
MockURLProtocol.swift
//
// File.swift
//
//
// Created by Lee Burrows on 04/01/2021.
//
import Foundation
class MockURLProtocol: URLProtocol {
@TheiOSDude
TheiOSDude / NSDictionaryValueForWhat.swift
Created October 16, 2019 10:51
Highlighting an important, yet probably overlooked, instance method on NSDictionary where the key starts with '@'
import UIKit
var dictionary = NSMutableDictionary()
let key = "@123"
dictionary[key] = "Test Value"
let value = dictionary[key] // Test Value
let newKey = "@4321"
dictionary[newKey] = "New Test Value"
@TheiOSDude
TheiOSDude / deleteSimApp.sh
Last active August 29, 2018 13:45
delete iOS app from booted simulator as a run script
xcrun simctl uninstall booted com.theiosdude.bundleid