The queryA method returns an array of ARecords each of which contains an IPAddress.
IPAddress is an abstract protocol with two conforming protocols, IPv4Address and IPv6Address.
I expect a v4 but I’ve run out of ideas on how to do the coercion. My latest attempt was
If let v4 = ipaddress as IPv4Address {
// do my thing here
}
But this gives the error “Cannot convert value of type ‘IPAddress’ to type ‘IPv4Address’ in coercion.
and
> If let v4 = ipaddress as? IPv4Address {
> // do my thing here
> }
gives Cast from 'IPAddress' to unrelated type 'IPv4Address' always fails
Ideas?
I assume you're referring to swift-async-dns-resolver. Looking at the code in that repository, I see that IPAddress is an enum with two cases (each with associated type String), not a protocol, and I don't see any type or protocol named IPv4Address.
Ah, that documentation refers to a different library. Two libraries can define distinct types or protocols with the same name. If you're using swift-async-dns-resolver, then IPAddress isn't a protocol but an enum.
If you want to convert between AsyncDNSResolver.IPAddress and Network.NWEndpoint.IPv4Address, then you're going to have to destructure the IPAddress value to get the string value and use that to initialize the IPv4Address value.