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: James Spencer <email@hidden>
- Date: Sat, 18 Dec 2004 10:00:46 -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]];
...
[BOOL someMethodReturningBOOL];
doesn't work because BOOL is not a a class.
I could do something like this ...
if (someMethodReturningBOOL)
return Yes;
else
return NO;
but that would seem a bit of a kludge.
so how do you properly return the result of a method that returns BOOL?
This has nothing to do with Cocoa but rather is an Objective C problem.
You need to read the Objective C documentation more closely as well as
pay better attention to warning messages from Xcode more closely as
this problem is very similar to the one you posted on the AppleScript
Studio list. The problem here has nothing to do with how you return
BOOL's from a method. But as a warning message should have told you, a
BOOL is not a class which means that res is not an object which means
it doesn't respond to messages.
If you DID have an object that returned a BOOL then you just return
them like you put in your code above:
return [res is10digitNANPA:[aString substringFromIndex:index]];
This would work just fine IF res were an object that responded to the
is10digitNANPA message, i.e. if there was a class MyClass which
contained this message declared:
-(BOOL)is10digitNANPA:(NSString *)input
Then you could do
MyClass *res = [[MyClass alloc]init]
...;
return [res is10digitNANPA:someString];
Probably even better, as at least on the little you have shown here,
MyClass doesn't use any instance variables to determine whether is a
string is10digitNANPA, would be to declare the method as a class method
so you don't even have to create a res object:
+(BOOL)is10digitNANPA:(NSString *)input
then you could simply:
return [MyClass is10digitNANPA:someString];
In the end, the question is where are you getting the is10digitNANPA:
method or function from?
James P. Spencer
Rochester, MN
email@hidden
"Badges?? We don't need no stinkin badges!"
_______________________________________________
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