I’m really new to Mac application building and I’m trying out some different techniques. I’m trying to figure out how to put in a basic login (username and password) screen into my app. In my method I currently have this, attempting to use the if else statements (the set background colour is just a temp replacement for opening the next window).
- (IBAction)loginb:(id)sender {
if (m_username == [@"haseo98" NSString]){
[_window setBackgroundColor:[NSColor redColor]];
}
else [_window setBackgroundColor:[NSColor blackColor]];
}
The main problem in my opinion is with this line:
if (m_username == [@"haseo98" NSString]){
How do I get XCode to read what’s in the NSTextfield and compare it to “haseo98”?
NSTextFieldis aNSControl, so you can use-stringValueto get the text content:To compare the strings, use
-isEqualToString::Note that comparing strings using
==doesn’t usually do what you want and that string literals (@"text") are alreadyNSStringinstances.