iOS Swift Native URLSession Client
Swift async/await and Codable struct mapping for native iOS apps.
Mobile App SDKs
Native Swift iOS integration with URLSession, async/await, and Codable models for Apple platforms.
Quick Start
Swift BaziClient Class
Swift
import Foundation
struct BaziRequest: Encodable {
let birthDate: String
let birthTime: String
let gender: String
}
class BaziClient {
let apiKey: String
init(apiKey: String) { self.apiKey = apiKey }
func calculate(birthDate: String, birthTime: String, gender: String) async throws -> [String: Any] {
var req = URLRequest(url: URL(string: "https://api.baziapi.pro/api/v1/bazi/calculate")!)
req.httpMethod = "POST"
req.setValue(apiKey, forHTTPHeaderField: "x-api-key")
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.httpBody = try JSONEncoder().encode(BaziRequest(birthDate: birthDate, birthTime: birthTime, gender: gender))
let (data, _) = try await URLSession.shared.data(for: req)
return try JSONSerialization.jsonObject(with: data) as! [String: Any]
}
}Something unclear? Contact developer support.