我的代码
NSString-Utilities.h:
- C/C++ code
#import <Cocoa/Cocoa.h>#import <NSString.h>@interface NSString(Utilities) -(BOOL) isURL;@end
NSString-Utilities.m:
- C/C++ code
#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:
- C/C++ code
#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];}
编译没问题,运行时提示 NSConstantString (instance) does not recognize isURL
本人新手。。大家帮忙看看谢谢。
------解决方案--------------------
将实例方法改为类方法试试,提示的已经比较清楚了。
------解决方案--------------------
把类的名称改一下,不要随便在名字中加-等符号