Search code examples
iphoneobjective-cinterface-builderconnectionnsscanner

Problem with NSScanner in the IB connections


This maybe a silly question, but I am having a problem with the NSScanner. I have a UITextField in which the text needs to be taken. I cannot seem to get the NSScanner field connected in Interface Builder. Can you please help?

My file has the following code:

- (IBAction)getUserPassword:(NSScanner *)sender {
    NSCharacterSet *theCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@"1234567890abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+<>?,./:\";'[]\{}| "];
    [userEntered scanCharactersFromSet:theCharacterSet intoString:&temp];
}

Solution

  • It looks like you're trying to connect NSScanner like a UI object. NSScanner isn't a UI object. Did you mean this instead?

    - (IBAction)getUserPassword:(UITextField *)textField {
        NSScanner *userEntered = [NSScanner scannerWithString:textField.text];
        NSString *temp = nil;
        NSCharacterSet *theCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@"1234567890abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+<>?,./:\";'[]\{}| "];
        [userEntered scanCharactersFromSet:theCharacterSet intoString:&temp];
        ...
    }