Generics II en Swift: conditional conformance, where clauses y extensiones genéricas

Cuando necesitas almacenar un tipo existencial de un genérico con associated types, Swift usa type erasure: un wrapper que oculta el tipo concreto:

import SwiftUI
import Combine

// AnyPublisher oculta el tipo concreto del Publisher
func obtenerNombre() -> AnyPublisher {
    URLSession.shared
        .dataTaskPublisher(for: URL(string: "https://api.ejemplo.com")!)
        .map { String(data: $0.data, encoding: .utf8) ?? "" }
        .eraseToAnyPublisher()  // type erasure
}

COMPARTE ESTE ARTÍCULO

COMPARTIR EN FACEBOOK
COMPARTIR EN TWITTER
COMPARTIR EN LINKEDIN
COMPARTIR EN WHATSAPP