A few problems:
- In C (and Objective-C) a single equal sign as you have used is for assignment, not comparison
- Secondly, the proper way to do string comparison in Objective-C is to use the
NSString
method isEqualToString:
- Objective-C uses
nil
instead of null
- In Objective-C a pointer is nil it will evaluate to false, so instead of using
isEqual
you can just test !secretPin
(which will return true is secretPin is nil)
- As others have pointed out, your parentheses are incorrectly set in your conditional
So a more correct rewrite is:
if ( [self.nametextfield.text isEqualToString:@""] || !secretPin ) {
// do something
}
EDIT:
Also note that I have edited this example so that nametextfield
is now a property of self
(where self
in this case is your View Controller). The "unexpected identifier" error makes me think you have not connected your Text Field object (created in your storyboard or xib file) to your view controller correctly. You should be sure you are declaring the text field as a property of your view controller like this in your header (.h) file:
@property (nonatomic, weak) IBOutlet UITextField* nametextfield;
and synthesize the property in your implementation (.m) file:
@synthesize nametextfield;
and then attach the UITextField in your storyboard or xib to this IBOutlet.