iosobjective-cuitextfieldnsuinteger

Define a minimum number character in UITextfield


I wish verify a number letter in UITextfield, and also if my textfield is empty. But, I have a problem between NSUInteger and int. Thanks for your answers.

- (void)saveProfile {

    NSUInteger *minID = [_userID.text length];

    if ([_userID.text isEqualToString:@""] == NO || minID >= 4) {
         // Succes
    } else { // Error }
}

Solution

  • Change this code:

    NSUInteger *minID = [_userID.text length];
    

    to

    NSUInteger minID = [_userID.text length];
    

    The length property is defined like:

    @property(readonly) NSUInteger length 
    

    So the length getter method will return a NSUInteger not NSUInteger *

    Refer : NSString class reference for more details