Skip to content

Instantly share code, notes, and snippets.


Lincoln Wu CrystDragon

View GitHub Profile
CrystDragon / Sequence+max.swift
Created Jun 20, 2019
A type-erased keyPath-based multi-argument max helper
View Sequence+max.swift
/// library
/// a type-erased interface
private final class ComparatorHolder<S: Sequence> {
private typealias Comparator = (S.Element, S.Element) -> Int
private let base: S
private var comparators: [Comparator] = []
CrystDragon / TestViewProperties.swift
Last active Aug 22, 2018
Test relations between main properties of `UIView`
View TestViewProperties.swift
import UIKit
extension UIView {
func dumpProperties() {
- bounds: \(bounds)
- frame: \(frame)
- center: \(center)
CrystDragon / ExploreSRGB.swift
Last active Jan 27, 2021
Explore gamma correction related properties on iOS
View ExploreSRGB.swift
// test in playground targeting iOS
import UIKit
import QuartzCore
let sRGBSpace = CGColorSpace(name: CGColorSpace.sRGB)!
let linearSpace = CGColorSpace(name: CGColorSpace.linearSRGB)!
func dumpImageFirstPixel(_ image: UIImage) {
guard let cgImage = image.cgImage,
let dataBuffer = cgImage.dataProvider?.data as Data?,
CrystDragon / MyTextLabel.swift
Created May 17, 2018
Most basic custom UITextInput conformance, without selection interaction, no UI elements but only pure texts.
View MyTextLabel.swift
import UIKit
class MyTextLabel: UIView {
var textLayer = CATextLayer()
var textStorage: String = "" {
didSet {
textLayer.string = textStorage