Bronze Challenge using NSMutableCharSet

I created a custom character set using NSMutableCharSet.
The allowed characters are ‘1234567890-.’.

[code]func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

    print("current \(textField.text)")
    print("replacement \(string)")
    
    let existingTextHasDecimalSeparator = textField.text?.rangeOfString(".")
    let replacementTextHasDecimalSeparator = string.rangeOfString(".")
    
    let decimalChars = NSMutableCharacterSet.decimalDigitCharacterSet()
    decimalChars.addCharactersInString("-.")
    let replacementTextHasDecimalCharsOnly = string.rangeOfCharacterFromSet(decimalChars)
    
    // a blank replacement string signifies delete
    if string == "" {
        return true
    } else if existingTextHasDecimalSeparator != nil && replacementTextHasDecimalSeparator != nil {
        return false
    } else if replacementTextHasDecimalCharsOnly != nil {
        return true
    } else {
        return false
    }  

}[/code]