Consider two models defined like this:
struct User {
let id: Int
let name: String
let email: String
}
/** | |
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 { |
/* | |
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 |
/* | |
Given an array with optional sub-arrays, how can I flatten the array? | |
Example: | |
Given [[1, 2], nil, [3]] | |
Expect [1, 2, 3] | |
Solution: |
// 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, |
// | |
// TableviewDatasource.swift | |
// | |
// Created by Phlippie Bosman on 2019/01/30. | |
// Copyright © 2019 Kalido. All rights reserved. | |
// | |
import Reusable | |
import SwiftLCS |
/// Synched operations will only run one at a time. | |
/// The `operation` method is responsible for calling `complete` to notify the object when it is done. | |
final class SyncedOp { | |
// Use a GCD Semaphore to synchronize flag access. | |
private let semaphore = DispatchSemaphore(value: 1) | |
private var isBusy = false | |
private var isRetriggerQueued = false | |
internal var operation: () -> () = {} |
/* | |
This code demonstrates a way to get UITableViewCells to resize | |
after their content size has changed, without needing to reload | |
the cells. | |
Prerequisites: | |
- The table view must be set up to calculate its cell heights dynamically; i.e. | |
tableView.rowHeight = UITableView.automaticDimension | |
tableView.estimatedRowHeight = 100 // or some good estimate | |
- The cell must be laid out using auto layout. Remember to add the subviews to |
// | |
// LightRibbon2.swift | |
// Waveforms | |
// | |
// Created by Phlippie Bosman on 2018/04/12. | |
// Copyright © 2018 Phlippie Bosman. All rights reserved. | |
// | |
import UIKit |
# To get this: | |
# curl -Lo $HOME/.screenrc 'https://goo.gl/bZv3x2' | |
# Enable mouse scrolling: | |
termcapinfo xterm* ti@:te@ | |
# Clear screen when vim/less/etc quits: | |
altscreen on | |
# Status line that shows windows: |