Skip to content

Instantly share code, notes, and snippets.

@el-hoshino
el-hoshino / AssociativeComparisonPrecedence.swift
Last active February 5, 2024 22:40
AssociativeComparison
precedencegroup AssociativeComparisonPrecedence {
associativity: left
higherThan: ComparisonPrecedence
lowerThan: NilCoalescingPrecedence
}
infix operator <: AssociativeComparisonPrecedence
infix operator <=: AssociativeComparisonPrecedence
public func < <V: Comparable>(lhs: V, rhs: V) -> (Bool, V) {
@unixzii
unixzii / ContentView.swift
Last active March 30, 2024 08:36
GPU particle system using Metal.
import SwiftUI
struct SmashableView: NSViewRepresentable {
typealias NSViewType = _SmashableNSView
let text: String
class _SmashableNSView: NSView {
@realvjy
realvjy / ChoasLinesShader.metal
Last active April 16, 2025 00:45
Choas Lines - Metal Shader
// Lines
float hash( float n ) {
return fract(sin(n)*753.5453123);
}
// Slight modification of iq's noise function.
float noise(vector_float2 x )
{
vector_float2 p = floor(x);
vector_float2 f = fract(x);
@Alex-Ozun
Alex-Ozun / typestate-tesla-car.swift
Last active March 22, 2024 10:03
Typestate in Swift
enum Parked {}
enum Driving {}
enum Gaming {}
private class EngineSystem {
static var shared = EngineSystem()
private init() {}
func start() {/**/}
func accelerate() { /* Uses gas pedal input to accelerate the real car */ }
@unixzii
unixzii / WeatherView.swift
Created November 7, 2023 13:21
A demo of implementing iOS Weather card in SwiftUI.
import SwiftUI
struct HeaderView: View {
var body: some View {
HStack {
Image(systemName: "info.circle.fill")
.resizable()
.frame(width: 12, height: 12)
Text("Section Header")
.font(.system(size: 13))
@timsneath
timsneath / dragcard.swift
Created October 17, 2023 04:46
Small sample of a draggable card object in SwiftUI
// Adapted from Hacking with SwiftUI, credit to Paul Hudson (@twostraws).
// https://www.hackingwithswift.com/books/ios-swiftui/animating-gestures
import SwiftUI
struct ContentView: View {
@State private var dragAmount = CGSize.zero
var body: some View {
RoundedRectangle(cornerRadius: 10)
@DominatorVbN
DominatorVbN / ChoasGame.swift
Created October 1, 2023 09:25
Simulation of mathematical concept of Chaos Game
import SwiftUI
import SwiftData
// TODO: Make this animatable shape
struct Polygon: Shape {
var edges: Int
var pathUpdated: (Path) -> Void
var vertexUpdated:([CGPoint]) -> Void
import UIKit
/// このプロトコルで画面遷移のインターフェースを共通化
protocol Coordinator {
func start()
}
/// 初期起動経路を管理するクラス
final class AppCoordinator: Coordinator {
// プロパティとしてUIWindowとUINavigationControllerを保持する
@minsOne
minsOne / DataState.swift
Last active September 26, 2023 11:11
SwiftUI DataState
enum DataState<V, E: Error> {
case idle
case initialLoading case reLoading (V)
case retryLoading (E)
case success (V)
case failure(E)
case paging (V)
case pagingFailure(V, E)
}
@YusukeHosonuma
YusukeHosonuma / ContentView.swift
Created August 29, 2023 04:41
SwiftUI: 某エディタの透明度アイコン的な
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
OpacityIcons(content: OpacityIcon1.init)
OpacityIcons(content: OpacityIcon2.init)
}
.padding()
}