Skip to content

Instantly share code, notes, and snippets.

View pkclsoft's full-sized avatar

Peter Easdown pkclsoft

View GitHub Profile
@runys
runys / SquareGame-After.swift
Last active July 14, 2023 01:28
Example code of a simple integration between SwiftUI and SpriteKit using the delegate pattern.
import SwiftUI
import SpriteKit
protocol SquareGameLogicDelegate {
var totalScore: Int { get }
mutating func addPoint() -> Void
}
// 1. Conform the ContentView to the SquareLogicDelegate protocol
@importRyan
importRyan / whenHovered.md
Last active May 11, 2024 03:13
Reliable SwiftUI mouse hover

Reliable mouseEnter/Exit for SwiftUI

Kapture 2021-03-01 at 14 43 39

On Mac, SwiftUI's .onHover closure is not always called on mouse exit, particularly with high cursor velocity. A grid of targets or with finer target shapes will often have multiple targets falsely active after the mouse has moved on.

It is easy to run back to AppKit's safety. Below is a SwiftUI-like modifier for reliable mouse-tracking. You can easily adapt it for other mouse tracking needs.

import SwiftUI
@darkseed
darkseed / Reachability.h
Created August 30, 2011 23:16 — forked from dhoerl/Reachability.h
Reachability (iOS) ARCified
/*
File: Reachability.h
Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
Version: 2.2 - ARCified
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software