Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / October 2005



Tip: Looking for answers? Try searching our database.

super simple Obj-C question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
deepstar@gmail.com - 19 Oct 2005 22:27 GMT
I've been trying to solve this isEqualToString problem for a day now
but can't wrap my head around it.

- (IBAction)btnPress:(id)sender
{
    if ( [[password stringValue] isEqualToString:@"Hello"] ) {
        [msgOut setStringValue:@"Open sesame"];
    }
}
@end

As you can see it's a simple function which compares a string to
another one, but I can't get the damned thing to work properly in
Cocoa. I've tried isolating [msgOut setStringValue:@"Open sesame"]; and
deleting the If statement, that works fine - the textbox says "Open
sesame" upon pressing the button so there's nothing wrong with my app
interface. It has to be a faulty If statement, right?
Patrick Machielse - 19 Oct 2005 23:21 GMT
> I've been trying to solve this isEqualToString problem for a day now
> but can't wrap my head around it.
[quoted text clipped - 13 lines]
> sesame" upon pressing the button so there's nothing wrong with my app
> interface. It has to be a faulty If statement, right?

the 'password' outlet is not connected.

patrick
deepstar@gmail.com - 19 Oct 2005 23:56 GMT
Thanks for taking the time Patrick, i can't believe i made such a
fundamental mistake. Btw, how did you know that it was the password
outlet?
Patrick Machielse - 20 Oct 2005 09:49 GMT
> Thanks for taking the time Patrick, i can't believe i made such a
> fundamental mistake.

Because it is valid in Objective-C to send messages to 'nil',
unconnected outlets don't generally raise errors. Everyone here
experienced it (at least) once and went on a wild bug chase.

> Btw, how did you know that it was the password
> outlet?

when the password outlet is not connected, it has the value 'nil',
and

   if ( [[password stringValue] isEqualToString:@"Hello"] )

evaluates to 'NO'. (which probably isn't guaranteed, because
isEqualToString returns a BOOL and not an object, but that's a finer
point)

patrick
clvrmnky - 24 Oct 2005 18:42 GMT
> Thanks for taking the time Patrick, i can't believe i made such a
> fundamental mistake. Btw, how did you know that it was the password
> outlet?

My guess: because the if statement fails unless the password id is
connected up properly.  That is, the final boolean is determined by the
whole statement; comparing an unconnected id in this manner will always
return false, it looks like.

By removing the if statement (or forcing it to true) the code worked,
and since the if statement was properly formed, the problem had to be in
the final result of the statement coming out to false.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.