Skip to content

Instantly share code, notes, and snippets.

@tokizuoh
Last active April 15, 2024 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokizuoh/53d46231fc60c9c9eba3b6f449023426 to your computer and use it in GitHub Desktop.
Save tokizuoh/53d46231fc60c9c9eba3b6f449023426 to your computer and use it in GitHub Desktop.
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