Skip to content

Instantly share code, notes, and snippets.

View JUSTINMKAUFMAN's full-sized avatar

Justin Kaufman JUSTINMKAUFMAN

View GitHub Profile
@natpenguin
natpenguin / SpreadsheetView.swift
Last active February 18, 2023 03:38
A view like spreadsheet in SwiftUI
import SwiftUI
struct SpreadsheetView<ColumnView: View, RowView: View, ContentView: View, Column: Hashable, Row: Hashable>: View {
init(
columns: [Column],
rows: [Row],
columnWidth: CGFloat,
columnHeight: CGFloat,
rowWidth: CGFloat,
rowHeight: CGFloat,
@JUSTINMKAUFMAN
JUSTINMKAUFMAN / XCFramework.kts
Created November 3, 2021 18:53
Kotlin Multiplatform Build Gradle Task for iOS/macOS Universal Framework
/**
* Kotlin Multiplatform Universal XCFramework Task
*
* Description:
* If your project needs to target *all* possible
* iOS and macOS variants (including Apple Silicon
* hardware, ARM64 iPhone simulators, and so on),
* this task will build the frameworks, lipo those
* that can be combined into a single binary, and
* place them where Xcode expects to find them in
@JUSTINMKAUFMAN
JUSTINMKAUFMAN / FunctionWrapper.swift
Created August 23, 2021 16:31
Function Wrapper Concept
/// Implementation
typealias AnyFunction = ((Any?, ((Any?) -> (Any?))?) -> (Any?))
@functionWrapper
struct Logging {
let value: AnyFunction
@discardableResult
func wrappedFunction(_ arguments: Any?, _ completion: ((Any?) -> (Any?))? = nil) -> Any? {
//
// VolumeSlider.swift
// TristateToggleProject
//
// Created by Matthew Young on 12/3/19.
// Copyright © 2019 Matthew Young. All rights reserved.
//
// https://stackoverflow.com/questions/58286350/how-to-create-custom-slider-by-using-swiftui
@CodeSlicing
CodeSlicing / OffsetToPositionDemo.swift
Last active September 21, 2023 01:07
Demonstrates the use of offsetToPosition modifier
//
// OffsetToPositionDemo.swift
//
// 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,
// subject to the following conditions:
@chriseidhof
chriseidhof / sample.swift
Last active June 11, 2024 06:11
View Inspection
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
}
}
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {
import Foundation
@propertyWrapper
struct ZeroDefaulting: Codable {
var wrappedValue: Int?
init(wrappedValue: Int?) {
print("set:", wrappedValue ?? "nil")
self.wrappedValue = wrappedValue
}
@AliSoftware
AliSoftware / Bindings.swift
Last active May 22, 2024 08:45
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
@JUSTINMKAUFMAN
JUSTINMKAUFMAN / CrashViewController.swift
Last active September 2, 2019 18:37
Crash when mutating [UIColor] in a struct on a UIView prior to adding that view as a UIViewController's subview
import UIKit
/**
This code *consistently* crashes when built with
the following Xcode 10.2.1 build settings:
`Swift Version` = `5` (i.e. default)
`Enable Testability` = `NO`
`Optimization Level` = `-Owholemodule`
@MCJack123
MCJack123 / BeatSaberLevelFormat.md
Last active September 11, 2021 22:47
Beat Saber 1.0 level format conversion
info.json Info.dat
+ _version = "2.0.0"
songName _songName
songSubName _songSubName
authorName _songAuthorName
+ _levelAuthorName = ""
beatsPerMinute _beatsPerMinute
difficultyLevels[].offset _songTimeOffset
Difficulty.json => _shuffle _shuffle