To reinforce what we have learned in this chapter, let's look at one more example. For this example, we will create a function that will test to see if a string value contains a valid IPv4 address or not. An IPv4 address is the address assigned to a computer that uses the Internet Protocol (IP) to communicate. An IP address consists of four numeric values, ranging from 0-255, separated by a dot (period). An example of a valid IP address is 10.0.1.250:
func isValidIP(ipAddr: String?) -> Bool { guard let ipAddr = ipAddr else { return false } let octets = ipAddr.characters.split { $0 == "."}.map{String($0)} guard octets.count == 4 else { return false } func validOctet(octet: String) -> Bool { guard let num = Int(String(octet)), num >= 0 && num < 256 else { return false...