Friday, December 27, 2013

About objective-c categories (Category), problems encountered novice help!

My code
NSString-Utilities.h:
 
# Import
# Import

@ Interface NSString (Utilities)
- (BOOL) isURL;
@ End


NSString-Utilities.m:
 
# Import "NSString-Utilities.h"

@ Implementation NSString (Utilities)

- (BOOL) isURL
{
if (self.length <7) return NO;

NSRange range = NSMakeRange (0,7);
NSString * prefix = [self substringWithRange: range];

if ([prefix isEqualToString: @ "http://"])
return YES;
else
return NO;
}

@ End


main.m:
 
# Import "NSString-Utilities.h"

int main (int argc, const char * argv []) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * string1 = @ "http://sdfing";
NSString * string2 = @ "sdfa";

if ([string1 isURL])
NSLog (@ "string1 is URL");
if ([string2 isURL])
NSLog (@ "string2 is URL");

[Pool release];
}




Compile no problem, NSConstantString (instance) does not recognize isURL
tips runtime
I am a novice. . Help us to see, thank you.

Reply:
I do not know the expression. Did not care for it. .
Reply:
The instance methods to class methods to try, Tip has been relatively clear.
Reply:
The change of the name of the class, not just in the name of Canada - symbols
Reply:
Thank you, upstairs, according to your question is resolved.

No comments:

Post a Comment