Skip to content

Instantly share code, notes, and snippets.

View heestand-xyz's full-sized avatar

Anton Heestand heestand-xyz

View GitHub Profile
@heestand-xyz
heestand-xyz / ContentModeAnimation.swift
Created March 15, 2024 22:00
SwiftUI Content Mode Animation
import SwiftUI
struct ContentView: View {
@State private var contentMode: ContentMode = .fit
var body: some View {
ZStack {
@heestand-xyz
heestand-xyz / FrameLayout.swift
Created January 22, 2024 02:46
Frame Layout
struct FrameLayout: Layout {
let frame: CGRect
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
CGSize(
width: proposal.width ?? 0.0,
height: proposal.height ?? 0.0
)
}
@heestand-xyz
heestand-xyz / allocation_test.swift
Created December 18, 2023 12:42
Swift Allocation Test
func allocationViewModel<T: AnyObject>(_ viewModel: inout T?, as name: String) {
weak var _viewModel: T?
autoreleasepool {
_viewModel = viewModel
viewModel = nil
}
extension XCTestCase {
func isDeallocated<T: AnyObject>(_ object: inout T?) -> Bool {
weak var _object: T?
autoreleasepool {
_object = object
object = nil
@heestand-xyz
heestand-xyz / video-stabilization.swift
Last active April 28, 2023 08:53
Video Stabilization in Swift with AsyncGraphics
// Created by Anton Heestand with the help of GPT-4
// AsyncGraphics: https://github.com/heestand-xyz/AsyncGraphics
import SwiftUI
import AsyncGraphics
import Vision
struct ContentView: View {
@State var graphic: Graphic?
@heestand-xyz
heestand-xyz / SplineDemo.swift
Last active August 27, 2022 17:20
Spline Demo in SwiftUI
//
// ContentView.swift
// Spline Demo
//
// Created by Anton Heestand on 2022-08-27.
//
import SwiftUI
struct ContentView: View {
@heestand-xyz
heestand-xyz / maskPath.swift
Last active August 26, 2022 17:04
SwiftUI Path to Image Mask
import SwiftUI
import TextureMap
extension Path {
public func maskImage(size: CGSize) -> TMImage! {
guard let context = CGContext(data: nil,
width: Int(size.width),
height: Int(size.height),
@heestand-xyz
heestand-xyz / Animator.swift
Last active November 30, 2023 01:09
Animator with Easing
import Foundation
import CoreGraphics
#if os(iOS)
import UIKit
#endif
struct Animator {
enum AnimationEase {
case linear
#if os(macOS)
import AppKit
#else
import UIKit
#endif
import SwiftUI
#if os(macOS)
typealias SomeImage = NSImage
#else
@heestand-xyz
heestand-xyz / ClampedValue.swift
Created June 12, 2020 07:09
Swift - Property Wrapper - Clamped Value
@propertyWrapper
struct ClampedValue<F: FloatingPoint> {
var value: F
let min: F?
let max: F?
init(wrappedValue: F, min: F? = nil, max: F? = nil) {
value = wrappedValue
self.min = min
self.max = max
}