Last active
April 15, 2024 06:24
-
-
Save tokizuoh/53d46231fc60c9c9eba3b6f449023426 to your computer and use it in GitHub Desktop.
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 | |
// ref: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/properties/#Property-Wrappers | |
@propertyWrapper | |
struct TwelveOrLess { | |
private var number = 0 | |
@MainActor | |
var wrappedValue: Int { | |
get { return number } | |
set { number = min(newValue, 12) } | |
} | |
} | |
struct SmallRectangle { | |
@TwelveOrLess var height: Int | |
@TwelveOrLess var width: Int | |
func f() { | |
print(Thread.isMainThread) // true or false? | |
} | |
} | |
Task.detached { | |
let rectangle = await SmallRectangle() | |
await rectangle.f() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment