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
func setupImminentAlarm() async throws { | |
let tenSecondsFromNow = Date().addingTimeInterval(3) | |
let schedule = Alarm.Schedule.fixed(tenSecondsFromNow) | |
try await scheduleAlarm(at: schedule) | |
} |
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
import AlarmKit | |
private func alarmAuthorization() async throws { | |
switch try await AlarmManager.shared.requestAuthorization() { | |
case .notDetermined: | |
try await alarmAuthorization() | |
case .authorized: | |
try await setupImminentAlarm() | |
case .denied: | |
showPermissionsDeniedAlert = true |
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
// Input | |
class SomeClass { } | |
let myClass: AnyObject = SomeClass() | |
type(of: myClass) | |
// Output | |
; ModuleID = 'output.ll' | |
source_filename = "output.ll" | |
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32" | |
target triple = "arm64-apple-macosx15.0.0" |
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
// Input | |
func dynamicType<T>(_ value: T.Type) -> Any.Type { | |
return value | |
} | |
let runtimeType = type(of: dynamicType(Int.self)) | |
// Output | |
; ModuleID = 'output.ll' | |
source_filename = "output.ll" |
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
// Input | |
type(of: Int.self) | |
// Output | |
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { | |
[%1: noescape **] | |
[global: ] | |
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): | |
%2 = integer_literal $Builtin.Int32, 0 // user: %3 | |
%3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4 |
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
// Input | |
func dynamicType<T>(_ value: T.Type) -> Any.Type { | |
return value | |
} | |
let runtimeType = type(of: dynamicType(Int.self)) | |
// Output | |
import Builtin | |
import Swift |
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
import Distributed | |
public distributed actor BotPlayer: Identifiable { | |
typealias ActorSystem = LocalTestingDistributedActorSystem | |
var ai: RandomPlayerBotAI | |
var gameState: GameState | |
public init(team: CharacterTeam, actorSystem: ActorSystem) { | |
self.actorSystem = actorSystem // first, initialize the implicitly synthesized actor system property |
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
@Test | |
func refreshBeers_tellsRepositoryToLoad() async throws { | |
sut = BeerViewModel(repository: mockBeerRepository) | |
mockBeerRepository.stubLoadBeersResponse = .success([]) | |
let exp = SwiftExpectation() | |
mockBeerRepository.didLoadBeers = { exp.fulfill() } | |
sut.refreshBeers() | |
try await exp.wait() | |
#expect(mockBeerRepository.loadBeersCallCount == 1) | |
} |
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
func test_refresh_loadsDataFromAPI() { | |
// given | |
mockAPI.stubFetchResponse = .success([]) | |
let exp = expectation(description: #function) | |
// when | |
viewModel.refresh() | |
mockAPI.didFetchData = { exp.fulfill() } | |
// then |
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
public final class MockAPI: API { | |
// mock result | |
public var stubFetchResponse: Result<[Model], Error>? | |
// deferred closure | |
public var didFetchData: (() -> Void)? | |
// what we assert | |
public private(set) var fetchDataWasCalled = false |