Skip to content

Instantly share code, notes, and snippets.

View phlippieb's full-sized avatar
🦆

Phlippie phlippieb

🦆
View GitHub Profile
//
// TableviewDatasource.swift
//
// Created by Phlippie Bosman on 2019/01/30.
// Copyright © 2019 Kalido. All rights reserved.
//
import Reusable
import SwiftLCS
// Say you have a generic class with a couple of generic types,
// that also takes a couple of parameters in its initializer:
class Foo<T, U, V> {
init(label: String, other: Any) {
// ...
}
}
// Instantiating objects of this class in the standard way, while not unusual,
/*
Given an array with optional sub-arrays, how can I flatten the array?
Example:
Given [[1, 2], nil, [3]]
Expect [1, 2, 3]
Solution:
@phlippieb
phlippieb / Sign in with Apple.swift
Last active September 30, 2019 06:25
Extremely simple sign in with apple test app
/*
In anticipation of iOS 13, I'm implementing Sign in with Apple.
To get started, I just made a simple VC that brings up the auth stuff, without even handling the result.
When running it in a simulator and completing the sign in process, the process appears to be broken:
- The auth controller is not dismissed
- `ASAuthorizationController`'s delegate method `authorizationController:didCompleteWithAuthorization` is not called
The code below is intended as a simple copy+paste to make problem replication easier:
1. Create a new XCode project
@phlippieb
phlippieb / Swift-Tagged.md
Created December 2, 2021 11:52
A pattern for preventing intermixed types that represent non-interchangeable concepts

The problem

Consider two models defined like this:

struct User {
  let id: Int
  let name: String
  let email: String
}
@phlippieb
phlippieb / ExactNumberOfIndices.swift
Created July 7, 2022 05:00
Leveraging Swift's type system to represent the concept of an index type with a fixed size
/**
Leveraging Swift's type system to represent the concept of an index type with a fixed size,
so that iterating over all indices doesn't require a default case.
*/
/// The abstract properties of a fixed-size index type
protocol ExactNumberOfIndices: CaseIterable, RawRepresentable where RawValue == Int {}
/// A concrete fixed-size index type with 1 element (namely 0)
enum _1: Int, ExactNumberOfIndices {