Loading...
Loading...
Expert in the Swift ecosystem, specializing in iOS/macOS/visionOS development, Swift 6 concurrency, and deep system integration.
npx skill4agent add 404kidwiz/claude-supercode-skills swift-expertmobile-app-developerbashpython-progame-developeractor ImageCache {
private var cache: [URL: UIImage] = [:]
func image(for url: URL) -> UIImage? {
return cache[url]
}
func store(_ image: UIImage, for url: URL) {
cache[url] = image
}
func clear() {
cache.removeAll()
}
}class ImageLoader {
private let cache = ImageCache()
func load(url: URL) async throws -> UIImage {
if let cached = await cache.image(for: url) {
return cached
}
let (data, _) = try await URLSession.shared.data(from: url)
guard let image = UIImage(data: data) else {
throw URLError(.badServerResponse)
}
await cache.store(image, for: url)
return image
}
}// 1. Define Key
private struct AuthKey: EnvironmentKey {
static let defaultValue: AuthService = AuthService.mock
}
// 2. Extend EnvironmentValues
extension EnvironmentValues {
var authService: AuthService {
get { self[AuthKey.self] }
set { self[AuthKey.self] = newValue }
}
}
// 3. Use
struct LoginView: View {
@Environment(\.authService) var auth
func login() {
Task { await auth.login() }
}
}@Observable
class Coordinator {
var path = NavigationPath()
func push(_ destination: Destination) {
path.append(destination)
}
func pop() {
path.removeLast()
}
func popToRoot() {
path.removeLast(path.count)
}
}
enum Destination: Hashable {
case detail(Int)
case settings
}@resultBuilder
struct RequestBuilder {
static func buildBlock(_ components: URLQueryItem...) -> [URLQueryItem] {
return components
}
}
func makeRequest(@RequestBuilder _ builder: () -> [URLQueryItem]) {
let items = builder()
// ... construct URL
}
// Usage
makeRequest {
URLQueryItem(name: "limit", value: "10")
URLQueryItem(name: "sort", value: "desc")
}swift-openapi-generatorHStack/VStack