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 | |
@main | |
struct GroupWithTaskApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
} | |
} |
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 | |
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 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 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 | |
/// An "extension" of FloatingPointFormatStyle that adds a `minusSign` API to customize | |
/// the character(s) used as the minus sign. | |
/// | |
/// You could add additional extensions by following the same pattern. | |
/// | |
/// All other APIs are copied from FloatingPointFormatStyle and forward to it for their | |
/// implementation. This isn’t a full replica of the FloatingPointFormatStyle API, though, | |
/// because it’s only intended as a proof of concept. |
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
<!-- | |
XSLT for removing unused namespaces from an XML file. | |
Author: Dimitre Novatchev | |
Source: https://stackoverflow.com/a/4594626 | |
License: CC BY-SA, https://creativecommons.org/licenses/by-sa/2.5/ | |
Usage: | |
xmlstarlet tr remove-unused-namespaces.xslt - |
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 | |
extension FormatStyle { | |
static func ordinal<FormatInput: BinaryInteger>() -> OrdinalFormatStyle<FormatInput> | |
where Self == OrdinalFormatStyle<FormatInput> | |
{ | |
OrdinalFormatStyle() | |
} | |
} |
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
// We can't use `Character` or `String` ranges directly because they aren't countable | |
// Create a countable range of ASCII values instead | |
let range = UInt8(ascii: "a")...UInt8(ascii: "z") // CountableClosedRange<UInt8> | |
// Convert ASCII codes into Character values | |
range.map { Character(UnicodeScalar($0)) } // Array<Character> | |
// → ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] |
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 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 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 | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
FrameworkView1 { | |
Text("FrameworkView1") | |
} | |
.border(.red) |
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
struct MyError: Error {} | |
func fireAndForget() async { | |
await withThrowingTaskGroup(of: Void.self) { group in | |
group.addTask { | |
print("child task start") | |
print("child task throws") | |
throw MyError() | |
} | |
// Notice that we're not awaiting the child task. |