Skip to content

Instantly share code, notes, and snippets.

@sahara-ooga
Created October 17, 2022 11:06
Show Gist options
  • Save sahara-ooga/05473657cfadaf76c2943a0334f5806c to your computer and use it in GitHub Desktop.
Save sahara-ooga/05473657cfadaf76c2943a0334f5806c to your computer and use it in GitHub Desktop.
swiftplaygroundでSwift Concurrencyを試す
// https://online.swiftplayground.run/ でSwift Concurrencyを試す用のサンプル
struct Example {
@available(macOS 10.15.0, *)
static func factors(for number: Int) async -> [Int] {
var result = [Int]()
for check in 1...number {
if number.isMultiple(of: check) {
result.append(check)
}
}
return result
}
}
if #available(macOS 10.15.0, *) {
let factors = await Example.factors(for: 120)
print("Found \(factors.count) factors for 120.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment