Re: How do you receive a BOOL from a method returning BOOL
Re: How do you receive a BOOL from a method returning BOOL
- Subject: Re: How do you receive a BOOL from a method returning BOOL
- From: Ricky Sharp <email@hidden>
- Date: Sat, 18 Dec 2004 09:52:11 -0600
On Dec 18, 2004, at 9:02 AM, BK [address used for mailing lists only]
wrote:
I have written a few Objective-C methods which I call from AppleScript
Studio apps.
So far I have always returned either a literal like 'return YES;' or a
local variable 'return myLocalVar;' or the result of a method call
where I could use the class name as the receiver such as in
return [NSString someMethodReturningNSString];
but now I have run into a very silly problem trying to return the
result of a method call that returns a BOOL. It would seem trivial but
I can't seem to work out how to do this. My code looks like this ...
return [res is10digitNANPA:[aString substringFromIndex:index]];
What type is 'res' here?
but that doesn't work. I have alo tried this ...
BOOL res;
...
res = [res is10digitNANPA:[aString substringFromIndex:index]];
NSLog(@"res: %@", res);
return res;
and it shows me that res is NULL.
From the looks here, are you attempting to send the is10digitNANPA:
message to your local variable 'res' which is of type BOOL?
If so, it's probably the case where res is initialized to a value of 0
(NULL). Sending a message to NULL then results in an assignment of
NULL to res.
[BOOL someMethodReturningBOOL];
doesn't work because BOOL is not a a class.
Hmm. I think you should read up on some of the basics.
I could do something like this ...
if (someMethodReturningBOOL)
return Yes;
else
return NO;
but that would seem a bit of a kludge.
This is a valid solution, but yes, a bit overkill. Depending upon
where your method lives, you'd have something like:
- (BOOL)foo
{
return [self someMethodReturningBOOL];
}
If someMethodReturningBOOL is a class method...
- (BOOL)foo
{
return [MyClass someMethodReturningBOOL];
}
or if its a message that can be sent to some instance...
- (BOOL)foo
{
return [someInstance someMethodReturningBOOL];
}
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden