some_id
some_id

Reputation: 29896

checking if a textfield is null

I currently add objects to an array with a label taken from the textfield input from the user.

At the moment it adds an entry even if the field is blank.

I assign the textfield to a string and then want to check if it is nil, if it is then dont add it to the array.

I am used to java where it could be done with something like

if(enteredText.length > 0){ //add to array}

I am trying the following in my code now

if(title != nil)
{
[plistArray addObject:title];
[plistArray writeToFile:filepath atomically: YES];
}

but it doesnt seem to work and there are no dot methods available to get the length of the entered text.

How could I achieve this in Obj-C?

Regards

Upvotes: 0

Views: 3613

Answers (1)

Michael Chinen
Michael Chinen

Reputation: 18697

Use the -length method of NSString

if(title != nil && [title length])
{
    [plistArray addObject:title];
    [plistArray writeToFile:filepath atomically: YES];
}

Upvotes: 4

Related Questions