Say the string is in hexadecimal, when the button (for auto-detection) is pressed it calls the hexadecimal string check boolean method and the spinner is supposed to go to the index of 1 (hexadecimal) and when the string is in Binary the binary string check is called and the spinner is supposed to be at index of 2 (binary).
So far, I have two boolean methods that are supposed to check the string using regular expression and return true if the string matches. The problem is, when I give the sub-program a binary string and press the button, it goes to hexadecimal and not binary. Here are the methods I have:
Code Block private func isStringHex(source: String) -> Bool { let reg = try! NSRegularExpression(pattern: "(0x)?([0-9a-f]{16})") let ran = NSRange(location: 0, length: source.count) if (reg.firstMatch(in: source, options: [], range: ran) != nil) { return true } return false } private func isStringBinary(source: String) -> Bool { let reg = try! NSRegularExpression(pattern: "([01]{2})") let ran = NSRange(location: 0, length: source.count) if (reg.firstMatch(in: source, options: [], range: ran) != nil) { return true } return false }