shajem
shajem

Reputation: 2121

Printing values of UITextField to NSLog

I have a Textfield, and when i print its text to a NSLog, i get the output as (null). I want to detect this how can i do this programatically.

I have tried several approaches and all of the following failed.

NSLog (@"Print %@ ", textfield.text);

if ([textfield.text isEqualToString:@""]) {}

if ([textfield.text isEqualToString:@"(null)"]) {}

if ([textfield.text isEqualToString:nil]) {}

How can i detect (null) which is returned when printed using NSLog ?

Upvotes: 1

Views: 2560

Answers (2)

iDhaval
iDhaval

Reputation: 7844

You can do it using

If([textField.text isEqualToString:@""])
{
    //Your code ....
}

or you can do it with

if(textField.text == Nil)
{
    //Your code ....
}

third option is that

if([textField.text length] == 0)
{
    //Your code ....
} 

Upvotes: 1

Michael Dautermann
Michael Dautermann

Reputation: 89509

I think you mean something like this:

if (textfield.text == nil)
{
    NSLog( @"textfield is nil");
} else {
    if( [textfield.text length] == 0 )
    {
        NSLog( @"textfield has zero length")
    } else {
       NSLog( @"textfield is %@", textfield.text);
    }
}

Upvotes: 4

Related Questions