Skip to content

Instantly share code, notes, and snippets.


Phlippie phlippieb

Block or report user

Report or block phlippieb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
phlippieb / Sign in with Apple.swift
Last active Sep 30, 2019
Extremely simple sign in with apple test app
View Sign in with Apple.swift
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
View flatmap_and_compactmap_combined.swift
Given an array with optional sub-arrays, how can I flatten the array?
Given [[1, 2], nil, [3]]
Expect [1, 2, 3]
View SwiftGenericTypesAsFactoryParameters.swift
// 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,
View TableviewDatasource.swift
// TableviewDatasource.swift
// Created by Phlippie Bosman on 2019/01/30.
// Copyright © 2019 Kalido. All rights reserved.
import Reusable
import SwiftLCS
View SyncedOp.swift
/// 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: () -> () = {}
phlippieb / ResizingTableViewCellDelegate.swift
Created Mar 15, 2019
Even when using AutoLayout and UITableView.automaticDimension, it's not obvious how to make your table view resize a cell when its content changes without reloading the entire cell. I've had success with calling beginUpdates() and endUpdates() on the table view after the content changes. This gist simply extracts that into a delegate.
View ResizingTableViewCellDelegate.swift
This code demonstrates a way to get UITableViewCells to resize
after their content size has changed, without needing to reload
the cells.
- 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
phlippieb / LightRibbonView.swift
Last active Apr 16, 2018
A UIView subclass that draws an animated light ribbon.
View LightRibbonView.swift
// LightRibbon2.swift
// Waveforms
// Created by Phlippie Bosman on 2018/04/12.
// Copyright © 2018 Phlippie Bosman. All rights reserved.
import UIKit
View .screenrc
# To get this:
# curl -Lo $HOME/.screenrc ''
# Enable mouse scrolling:
termcapinfo xterm* ti@:te@
# Clear screen when vim/less/etc quits:
altscreen on
# Status line that shows windows:
View CodeSynchronizationTests.swift
For use in an XCode Playground
import Foundation
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
// Method 1: Works
phlippieb / MaxHeightTextView.swift
Created Jan 25, 2017
`MaxHeightTextView` overrides `UITextView`'s `intrinsicContentSize` and `layoutSubviews` to allow it to grow to fit its content size, but only up to a specified max height. Once the text view reaches this max height, its content will start to scroll. Use with AutoLayout. Specifically, set up a fixed width, and two height constraints with greater…
View MaxHeightTextView.swift
// File.swift
// Kalido
// Created by Phlippie Bosman on 2016/11/17.
// Copyright © 2016 Kalido. All rights reserved.
class MaxHeightTextView: UITextView {
open var maxHeight: CGFloat?
You can’t perform that action at this time.