Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[HTTPClient] HTTPClient can not be used as an existential

Aperta
#55 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
swift
Ambito
api

Direzione di ricerca

Inizia ispezionando il protocollo HTTPClient e il suo requisito perform, quindi riproduci l'errore del compilatore con l'esempio WhateverAPI dell'issue. Determina se un valore any HTTPClient dovrebbe supportare questa chiamata e verifica che l'esempio venga compilato ed esegua la richiesta senza richiedere un tipo generico concreto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

http-client kind/usability

This code fails to compile:

@available(macOS 26.2, *)
struct WhateverAPI {

    let httpClient: any HTTPClient

    func doWhatever() async throws -> String {
        let request = HTTPRequest(method: .get, scheme: "https", authority: "www.example.com", path: "/foo")

        try await self.httpClient.perform(
            request: request,
            body: nil,
            configuration: .init(),
            eventHandler: EventHandler()
        ) { response, reader in

        }
    }
}

Fails to compile:

http_client_library.swift:15:24: error: member 'perform' cannot be used on value of type 'any HTTPClient'; consider using a generic constraint instead [#ExistentialMemberAccess]
13 |         let request = HTTPRequest(method: .get, scheme: "https", authority: "www.example.com", path: "/foo")
14 | 
15 |         try await self.httpClient.perform(
   |                        `- error: member 'perform' cannot be used on value of type 'any HTTPClient'; consider using a generic constraint instead [#ExistentialMemberAccess]
16 |             request: request,
17 |             body: nil,
Lingua principale
Swift
Stelle
70
Fork
24
Merge medio
9h 31m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apple/swift-http-api-proposal

Tutte le issue di apple/swift-http-api-proposal

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.