关于objective-c 类目(Category),遇到的问题新手求助!
我的代码
NSString-Utilities.h:
#import <Cocoa/Cocoa.h>#import <NSString.h>@interface NSString(Utilities) -(BOOL) isURL;@end
#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
#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];}