Skip to content

Instantly share code, notes, and snippets.

View jacobsapps's full-sized avatar

Jacob Bartlett jacobsapps

View GitHub Profile
func setupImminentAlarm() async throws {
let tenSecondsFromNow = Date().addingTimeInterval(3)
let schedule = Alarm.Schedule.fixed(tenSecondsFromNow)
try await scheduleAlarm(at: schedule)
}
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
// 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"
// 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"
// 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
// Input
func dynamicType<T>(_ value: T.Type) -> Any.Type {
return value
}
let runtimeType = type(of: dynamicType(Int.self))
// Output
import Builtin
import Swift
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
@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)
}
func test_refresh_loadsDataFromAPI() {
// given
mockAPI.stubFetchResponse = .success([])
let exp = expectation(description: #function)
// when
viewModel.refresh()
mockAPI.didFetchData = { exp.fulfill() }
// then
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