StrasbourgParkAPI

一个简单的 Swift 包,用于访问斯特拉斯堡停车场的开放数据(位置 API可用性 API

参考文档请见这里

用法

您可以使用回调闭包响应、Combine 或 async 方法与该框架交互

回调闭包

let client = ParkingAPIClient()
client.getLocations { (result) in
    switch result {
        case .success(let locations):
            print("Locations: \(locations)")
        case .failure(let error):
            print("Error during the download: \(error)")
    }
}

Combine

let client = ParkingAPIClient()
client.getLocationsPublisher().sink { result in
    if case .failure(let error) = result {
        print("Error: \(result)")
    }   
} receiveValue: { result in
    print("Response: \(result)")

}

async

let client = ParkingAPIClient()

do {
    let response = try await client.fetchLocations()
    print("Response: \(response)")
} catch let error {
    print("Error: \(error)")
}