Can a method return an NSRange?
Posted
by Dan Donaldson
on Stack Overflow
See other posts from Stack Overflow
or by Dan Donaldson
Published on 2010-04-07T20:57:40Z
Indexed on
2010/04/07
21:13 UTC
Read the original article
Hit count: 155
I have a method that returns an NSRange. When I call this method from outside the class I get a compile error.
NSRange tmpRange;
tmpRange = [phrase rangeInString:searchString forString:theLetter goingForward:YES];
return tmpRange.location == -1;
in the .h file:
#import <Foundation/Foundation.h>
@interface Phrase : NSObject {
}
- (NSRange) rangeInString:(NSString *) tgt forString:(NSString *) find goingForward:(BOOL) fwd;
@end
This method is called within the Phrase object by other methods without problems. The compiler says 'incompatible types in assignment'.
Can anyone explain this to me? I assume it has to do with returning an NSRange/struct type value generated outside the object, but I don't know why it works in one place and not the other.
© Stack Overflow or respective owner