Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
public extension View {
func extend<Content: View>(@ViewBuilder transform: (Self) -> Content) -> some View {
transform(self)
}
func `if`<T: View, F: View>(_ condition: Bool, @ViewBuilder _ then: (Self) -> T, @ViewBuilder `else`: (Self) -> F) -> some View {
condition ? ViewBuilder.buildEither(first: then(self)) : ViewBuilder.buildEither(second: `else`(self))
}
@kntkymt
kntkymt / ViewBuilderTest.swift
Last active October 27, 2023 06:57
ViewBuilderとifあれこれ
import SwiftUI
struct CounterView: View {
@State var counter = 0
var body: some View {
Button {
counter += 1
} label: {
Text(counter.description)
@kntkymt
kntkymt / Fixed sil_stage canonical
Last active May 4, 2024 10:37
`withUnsafeContinuation` doesn't inherit Actor Context SIL
TOOLCHAINS=org.swift.600202404301a swiftc -emit-sil main.swift
sil_stage canonical
import Builtin
import Swift
import SwiftShims
import Foundation
@MainActor func doSomething(a: Int) async
@kntkymt
kntkymt / auto call
Last active December 4, 2023 12:41
Objective-C async function SIL
sil_stage canonical
import Builtin
import Swift
import SwiftShims
import Foundation
@_hasStorage @_hasInitialValue @MainActor let myClass: MyClass { get }