This file contains hidden or 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
// SwiftUI question: How do you put a continuous background behind a GridRow? | |
// | |
// I would have thought: | |
// | |
// GridRow { … } | |
// .background { … } | |
// | |
// But this puts the background behind each cell individually (behaves like Group), | |
// which is not what I want. |
This file contains hidden or 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 | |
/// A wrapper view that provides a mutable Binding to its content closure. | |
/// | |
/// Useful in Xcode Previews for interactive previews of views that take a Binding. | |
struct Stateful<Value, Content: View>: View { | |
var content: (Binding<Value>) -> Content | |
@State private var state: Value | |
init(initialState: Value, @ViewBuilder content: @escaping (Binding<Value>) -> Content) { |
This file contains hidden or 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
// Structure of _StackLayoutCache and related types. | |
// Used by SwiftUI as the Cache type for VStackLayout and HStackLayout. | |
// | |
// As of: iOS 16.0 simulator in Xcode 14.0b6 | |
import SwiftUI | |
struct _StackLayoutCache { | |
var stack: StackLayout | |
} |
This file contains hidden or 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
// Excerpt from `SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64-apple-ios.swiftinterface` | |
// in Xcode 14.0b1 | |
// | |
// This is how any `Layout`-conforming type becomes a container view | |
// when it's used with a `@ViewBuilder` closure. | |
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | |
extension SwiftUI.Layout { | |
@_alwaysEmitIntoClient public func callAsFunction<V>(@SwiftUI.ViewBuilder _ content: () -> V) -> some SwiftUI.View where V : SwiftUI.View { | |
return _VariadicView.Tree( | |
root: _LayoutRoot(self), content: content()) |
This file contains hidden or 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
// I learned about `#if canImport(module, _version: x.y)` from Tony Allevato: | |
// https://forums.swift.org/t/pitch-sdk-conditional-code/52642/4 | |
// | |
// Does this work reliably? I have no idea! | |
// I have only done some quick experiments in a playground. | |
// | |
// The Foundation version in Xcode 14.0b1 is: | |
// - in iOS's Foundation.swiftinterface: 1932.104 | |
// - in macOS's Foundation.swiftinterface: 1932.401 | |
// |
This file contains hidden or 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 | |
extension LocalizedStringKey.StringInterpolation { | |
/// String interpolation support for links in Text. | |
/// | |
/// Usage: | |
/// | |
/// let url: URL = … | |
/// Text("\("Link title", url: url)") | |
mutating func appendInterpolation(_ linkTitle: String, link url: URL) { |
This file contains hidden or 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 Dispatch | |
@globalActor | |
final actor MyMainActor { | |
// Don’t allow others to create instances | |
private init() {} | |
// Requirements from the implicit GlobalActor conformance | |
typealias ActorType = MyMainActor |
This file contains hidden or 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 heterogeneous dictionary with strong types in Swift, https://oleb.net/2022/heterogeneous-dictionary/ | |
// Ole Begemann, April 2022 | |
/// A key in a `HeterogeneousDictionary`. | |
public protocol HeterogeneousDictionaryKey { | |
/// The "namespace" the key belongs to. Every `HeterogeneousDictionary` has its associated domain, | |
/// and only keys belonging to that domain can be stored in the dictionary. | |
associatedtype Domain | |
/// The type of the values that can be stored under this key in the dictionary. | |
associatedtype Value |
This file contains hidden or 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
// This is the code for https://forums.swift.org/t/communicating-between-two-concurrent-tasks/54240 | |
import _Concurrency | |
actor Buffer { | |
var elements: [Int] = [] | |
private var isNotEmpty: CheckedContinuation<Void, Never>? = nil | |
deinit { | |
// TODO: If the continuation is not nil, |
This file contains hidden or 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 _Concurrency | |
actor Channel<Output> { | |
private var conditionVar: CheckedContinuation<Output, Never>? = nil | |
deinit { | |
// TODO: if conditionVar != nil, resume it by throwing `CancellationError()`? | |
} | |
/// If there's no receiver, the sent value will be lost. |