Skip to content

Instantly share code, notes, and snippets.

View Noobish1's full-sized avatar

Blair McArthur Noobish1

View GitHub Profile
import Foundation
// MARK: - Extensions
extension URL {
var isDirectory: Bool {
(try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true
}
}
@ole
ole / swift-has-feature.sh
Last active April 12, 2025 11:59
swift-list-features: List Swift compiler upcoming and experimental feature flags. · swift-has-feature: Check if a given compiler knows a specific feature flag, and whether it's an upcoming or experimental flag.
#!/bin/zsh
# Test if the Swift compiler knows about a particular language feature.
#
# Usage:
#
# swift-has-feature [--swift SWIFT_PATH] [--language-version LANGUAGE_VERSION] FEATURE
#
# The feature should be an upcoming or experimental language feature,
# such as `"StrictConcurrency"` or `"ExistentialAny"`.
//
// Created by Sean Heber on 8/11/22.
//
import Foundation
enum ExponentialBackoffError : Error {
case retryLimitExceeded
}
//
// View+Assign.swift
// Created by Sean on 7/29/22.
//
import SwiftUI
// You cannot safely assign to a state variable during view update - such as inside the block of a GeometryReader.
// Rather than do an unsafe hack like DispatchQueue.main.async or resorting to a PreferenceKey or even Combine, we
// can simply defer the assignment to a time when it *is* safe to update State- such as inside of the task block!
@swiftui-lab
swiftui-lab / grid-trainer.swift
Last active October 21, 2024 15:24
A grid trainer for Grid views
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: this learning tool is designed to showcase the different
// Grid and GridRow view options, added in SwiftUI 2022. It is part of the
// blog article: https://swiftui-lab.com/eager-grids
//
import SwiftUI
import UniformTypeIdentifiers
// The root view of the application
struct ContentView: View {
@joshdholtz
joshdholtz / ATinySampleApp.swift
Last active February 12, 2025 13:48
Super basic SwiftUI app (70 lines of code) with paywall using RevenueCat
import SwiftUI
import RevenueCat
struct Constants {
static let apiKey = "<your_api_key>" // Will look like: appl_bunchofotherstuffhere
static let entitlementName = "<your_entitlement_name>" // I use something like "pro"
}
@main
struct ATinySampleApp: App {
@ryanlintott
ryanlintott / LayoutThatFits.swift
Last active December 8, 2023 15:14
An alternative to ViewThatFits. Updated version can be found here: https://github.com/ryanlintott/LayoutThatFits
//
// LayoutThatFits.swift
// WWDC22Experiments
//
// Created by Ryan Lintott on 2022-06-08.
//
import SwiftUI
struct LayoutThatFits: Layout {
import Nimble
import Quick
/// Replacement for Quick's `it` which runs using swift concurrency.
func asyncIt(
_ description: String,
file: StaticString = #file,
line: UInt = #line,
closure: @MainActor @escaping () async throws -> Void
) {
import SwiftUI
import Combine
public struct ChangeObserver<V: Equatable>: ViewModifier {
public init(newValue: V, action: @escaping (V) -> Void) {
self.newValue = newValue
self.newAction = action
}
private typealias Action = (V) -> Void
@douglashill
douglashill / LazyLet.swift
Created April 22, 2020 08:04
A Swift property wrapper that implements ‘lazy let’. I.e. a read-only property that loads its value when first read. Not safe for access from multiple threads.
/// A Swift property wrapper that implements ‘lazy let’. I.e. a read-only property that loads its value when first read.
/// Not safe for access from multiple threads.
/// Does not work the same as the lazy keyboard because the property initialiser will run before self is available.
/// Adapted from https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-wrappers.md
@propertyWrapper enum LazyLet<Value> {
case uninitialised(() -> Value)
case initialised(Value)
init(wrappedValue: @autoclosure @escaping () -> Value) {
self = .uninitialised(wrappedValue)