let greenHex = hex.substring(with: Range<String.Index>(start: hex.index(hex.startIndex, offsetBy: 2), end: hex.index(hex.startIndex, offsetBy: 4)))
This is Swift3.0, hex is a string, but this code throws an error saying that:
Cannot invoke initializer for type 'Range' with an argument list of type '(start: String.Index, end: String.Index)'