Skip to content

Instantly share code, notes, and snippets.

@seanwoodward
seanwoodward / alignment-guides-tool.swift
Last active March 10, 2025 05:01 — forked from swiftui-lab/alignment-guides-tool.swift
A few updates to such a great example
// The SwiftUI Lab
// Website: https://swiftui-lab.com
// Article: https://swiftui-lab.com/alignment-guides
import SwiftUI
import Observation
extension EnvironmentValues {
@Entry var alignmentModel: Model = Model()
}
@mbrandonw
mbrandonw / FB10144005.md
Last active June 11, 2024 07:32
iOS 16 Navigation API feedbacks

How to execute logic when NavigationLink is tapped?

FB10144005

Currently it doesn't seem possible to execute additional logic when a navigation link is tapped with the new NavigationLink(value:) initializer. When the link is tapped it updates path state all the way back at the root NavigationStack to drive navigation, but there are many times where we need to perform logic after the tap and before the drill down.

For example, after tapping a link we may want to pre-emptively load some data to show on the drill down screen. Or we may want to perform some form validation. Or we may want to track some analytics. This does not seem possible with the current link API.

A workaround is to use Buttons instead of NavigationLinks, but then you lose all of the styling and affordances given to links, such as chevrons when used in List.

If the API for NavigationLink cannot be changed to accomodate for this, perhaps a new ButtonStyle could be introduced that allows regular buttons to take on the sty

@ultim8k
ultim8k / uuid.sh
Created October 10, 2019 09:32
Generate UUID in BASH/ZSH
### Source: https://coderwall.com/p/t_sz3q/generate-uuid-at-shell-prompt
# alias uuid="python -c 'import sys,uuid; sys.stdout.write(str(uuid.uuid4()))' | pbcopy && pbpaste && echo"
alias uuid="uuidgen | tr -d '\n' | tr '[:upper:]' '[:lower:]' | pbcopy && pbpaste && echo"
extension Never {
/// A developer facing statement explaining how program correctness has failed.
public struct Reason: CustomStringConvertible {
public let description: String
public init(_ rationale: String) {
self.description = rationale
}
}
}
// Angle+Trig.swift
// SwiftPlaneGeometry
#if os(Linux)
/// #error No Linux Support
#else
import Darwin
#endif
extension Angle {
@erica
erica / angle.swift
Last active November 13, 2017 02:28
// Angle.swift
// SwiftPlaneGeometry
// Represents the degree of turn between two straight
// lines with a common vertex
public struct Angle : CustomStringConvertible, Equatable {
/// The pi constant, the ratio of a circle's circumference to its diameter
public static let (pi, π) = (Double.pi, Double.pi)
extension Collection where
Indices.Iterator.Element: Equatable,
Index == Self.Indices.Iterator.Element
{
/// Returns optional value for safely indexed value
/// and nil if index is out of bounds
public subscript(safe index: Self.Index) -> Self.Iterator.Element? {
guard indices.contains(index) else { return nil }
return self[index]
}
/*
ericasadun.com
Sometimes letting go doesn't mean saying goodbye
*/
prefix operator ++
prefix operator --
postfix operator ++
// https://github.com/Liquidsoul/XCTestPlayground
import Foundation
let defaultMessage = ""
public func XCTAssert(
@autoclosure expression: () -> BooleanType,
_ message: String = defaultMessage
) -> String {
/*
Erica Sadun, http://ericasadun.com
Collections, Sequences, and Strides
Heavily curated. I'm kicking myself for not keeping
better notes.
When in doubt I may have attributed stuff with