Created
October 17, 2022 11:06
-
-
Save sahara-ooga/05473657cfadaf76c2943a0334f5806c to your computer and use it in GitHub Desktop.
swiftplaygroundでSwift Concurrencyを試す
This file contains hidden or 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
// 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