title: How can I validate IPv4 and IPv6 addresses in Swift?
body: <p>IPv4 addresses are relatively easy to validate: they have 4 octets, separated by digits.  Each octet is an integer ranging from 0-255.</p>
  
  <p>IPv6 addresses are difficult to validate.  They have 8 hextets, each with 4 hexadecimal digits, separated by colons.  IPv6 addresses also have shortening rules where leading zeros in each hextet can be removed (leaving at least one zero in each hextet).  Additionally one or more consecutive :0: hextets can be shortened to ::, but only once in each IPv6 address.</p>
  
  <p>How can I validate IPv4 and IPv6 addresses in Swift?</p>