Skip to content

Instantly share code, notes, and snippets.

@rayfix
rayfix / DemoLister.swift
Created December 11, 2021 19:57
Using IdentifiedCollection package to manage large lists in SwiftUI
//
// ContentView.swift
// DemoLister
//
// Created by Ray Fix on 12/11/21.
//
import SwiftUI
import IdentifiedCollections
@rayfix
rayfix / boolean-sequences.swift
Created July 10, 2021 23:32
R-Style Boolean Sequence Selectors in Swift
extension Sequence where Element: Comparable {
static func ==(_ lhs: Self, _ rhs: Element) -> LazyMapSequence<Self, Bool> {
lhs.lazy.map { $0 == rhs }
}
static func !=(_ lhs: Self, _ rhs: Element) -> LazyMapSequence<Self, Bool> {
lhs.lazy.map { $0 != rhs }
}
static func <(_ lhs: Self, _ rhs: Element) -> LazyMapSequence<Self, Bool> {
//
// ContentView.swift
// CopyOnWrite
//
// Created by Ray Fix on 3/27/21.
//
import SwiftUI
struct CowType {
//
// ContentView.swift
// Slider
//
// Created by Ray Fix on 2/20/21.
//
import SwiftUI
struct VolumeView: View {
//
// ContentView.swift
// PickerDemo2
//
// Created by Ray Fix on 1/23/21.
//
import SwiftUI
// A slitghtly silly example of a fixed array prototype
enum SmallArrayEnum<E>: RandomAccessCollection, MutableCollection {
init() {
self = .count0
}
var startIndex: Int { 0 }
var endIndex: Int {
@rayfix
rayfix / DataGrid.swift
Created November 14, 2020 20:50
A SwiftUI 2D Grid
//
// ContentView.swift
// DataGrid
//
// Created by Ray Fix on 11/14/20.
//
import SwiftUI
struct DataGrid<Element> {
//
// ContentView.swift
// PhotoPicker2
//
// Created by Ray Fix on 10/31/20.
//
import SwiftUI
import PhotosUI
import UIKit
import SwiftUI
import PhotosUI
final class ViewModel: ObservableObject {
@Published var image: UIImage?
}
struct Spinner: UIViewRepresentable {
let isAnimating: Bool
// Algorithm from https://en.wikipedia.org/wiki/Permuted_congruential_generator
struct PRNG: RandomNumberGenerator {
var state: UInt64 = 0x4d595df4d0f33173
let multiplier: UInt64 = 6364136223846793005
let increment: UInt64 = 1442695040888963407
init(seed: UInt64) {
state = seed &+ increment