Objective-c Category(类别)

NSStringUtilities.h:

#import <Foundation/Foundation.h>
@interface NSString(Utilities) -(BOOL) isURL; @end

NSStringUtilities.m

#import "NSStringUtilities.h"
@implementation NSString(Utilities)
-(BOOL) isURL
{
if ([self hasPrefix:@"http://"]) {
return YES;
}else{
return NO;
}
}
@end

main.m:

#import <Foundation/Foundation.h>
#import "NSStringUtilities.h"
int main(void)
{
@autoreleasepool {
NSString* string1=@"http://www.google.com";
NSString* string2=@"Pixar"; if ([string1 isURL]) {
NSLog(@"string is a url");
}
if ([string2 isURL]) {
NSLog(@"string2 is a url");
}
}
}

console log:

2013-09-20 12:19:54.708 Obj-c[286:303] string is a url

上一篇:JavaWeb开发环境配置


下一篇:IOS多线程(NSThread)