Return to Snippet

Revision: 19221
at October 18, 2009 08:24 by gerhardsletten


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

#import "NSString-Utilities.h"
@implementation NSString (Utilities)

- (BOOL) isURL {
    if ( [self hasPrefix:@"http://"] )
        return YES;
    else
        return NO;
}
@end

// To use this:

NSString* string1 = @"http://pixar.com/";
NSString* string2 = @"Pixar";

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

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

Initial URL
http://www.cocoadevcentral.com/d/learn_objectivec/

Initial Description

                                

Initial Title
Categories in Objective-C

Initial Tags

                                

Initial Language
Objective C