This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// MARK: - Extensions | |
extension URL { | |
var isDirectory: Bool { | |
(try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Sean Heber on 8/11/22. | |
// | |
import Foundation | |
enum ExponentialBackoffError : Error { | |
case retryLimitExceeded | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LayoutThatFits.swift | |
// WWDC22Experiments | |
// | |
// Created by Ryan Lintott on 2022-06-08. | |
// | |
import SwiftUI | |
struct LayoutThatFits: Layout { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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) |
NewerOlder