Skip to content

Instantly share code, notes, and snippets.

View heestand-xyz's full-sized avatar

Anton Heestand heestand-xyz

View GitHub Profile
extension XCTestCase {
func isDeallocated<T: AnyObject>(_ object: inout T?) -> Bool {
weak var _object: T?
autoreleasepool {
_object = object
object = nil
@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
}
@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 / 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 / CancellableDragGesture.swift
Last active September 2, 2024 07:37
Cancellable Drag Gesture
import SwiftUI
struct ContentView: View {
@State private var isDragging: Bool = false
@GestureState private var isDraggingActive: Bool = false
var body: some View {
ZStack {
if isDragging {