Skip to content

Instantly share code, notes, and snippets.

View SintraWorks's full-sized avatar

António Nunes SintraWorks

View GitHub Profile
@SintraWorks
SintraWorks / BitField.swift
Created May 1, 2023 10:14
A BitField provides storage for a set a flags representing bits
import Foundation
/// A `BitField` is a struct that provides storage for a set a flags,
/// where each flag represents a bit either being set or not set (clear).
///
/// `BitField` is closely related to Swift's `OptionSet`, but it specializes
/// on treating bits as bits, rather than as abstract flags.
public struct BitField<T: UnsignedInteger> {
/// `naturalSize` represents the maximum number of bits that a `BitField` can hold, depending on the
/// size of the type over which it is generic.
@SintraWorks
SintraWorks / PleasantNavigationController.swift
Last active September 14, 2022 08:16
A navigation controller that does a better job at communicating navigation events
//
// PleasantNavigationController.swift
// NavControllerTest
//
// Created by Antonio Nunes on 23/08/2018.
// Copyright © 2018 SintraWorks.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
@SintraWorks
SintraWorks / SwiftUIPickerWheelWithAvoidance.swift
Created August 22, 2022 09:12
Show a SwiftUI control from the bottom and implement avoidance
//: A UIKit based Playground for presenting user interface
import SwiftUI
import PlaygroundSupport
import Combine
struct ContentView: View {
@State var showPicker = false
@State var selection: String = "€1.500"
@State var pickerHeight: CGFloat = 0
@SintraWorks
SintraWorks / ScrollingStackView.swift
Last active May 2, 2022 13:46
A scrolling capable drop-in replacement for UIStackView.
//
// ScrollingStackView.swift
//
// Created by Antonio Nunes on 05/08/2018.
// Copyright © 2018 SintraWorks. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@SintraWorks
SintraWorks / MicroLayoutDSL.playground
Created December 28, 2017 04:54
Mini Autolayout DSL
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
typealias PairedConstraint = (_ view: UIView, _ otherView: UIView) -> NSLayoutConstraint
typealias UnpairedConstraint = (_ view: UIView) -> NSLayoutConstraint
enum ConstraintRelation {
case equal, greaterThanOrEqual, lessThanOrEqual
import Foundation
/// Provides NSRegularExpression pattern matching against strings
/// in `switch` expressions
///
/// Regular expressions are expensive to construct. The built-in
/// class cache stores already-constructed pattern instances using
/// the pattern string (coerced to `NSString`) as its keys. Modify
/// matching options at the `match(_, options:)` call-site if needed.
///
@SintraWorks
SintraWorks / MiniAutoLayoutDSL_r2.playground
Last active January 6, 2018 11:10
Mini Auto Layout DSL revisited
import UIKit
import PlaygroundSupport
typealias Constraint = (_ view: UIView, _ otherView: UIView?) -> NSLayoutConstraint
enum ConstraintRelation {
case equal, greaterThanOrEqual, lessThanOrEqual
}
func constraint<Anchor, AnchorType>(_ keyPath: KeyPath<UIView, Anchor>,