Aleksey Potapov
Aleksey Potapov

Reputation: 3783

Error with Categories iPhone

I've Category problem : No visible @interface for 'NSString' declares in selector 'isUrl'

NSString+NSString.h

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

NSString+Nsstring.m

#import "NSString+NSString.h"

@implementation NSString (NSString)

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

ViewController.m

#import "ViewController.h"
#import "NSString+NSString.h"
@implementation ViewController
    - (void)viewDidLoad
    {
        [super viewDidLoad];
            NSString* string1 = @"http://apple.com/"; 
            NSString* string2 = @"Apple";
            if ([string1 isURL]) {  // **Here is an error** 
                NSLog (@"string1 is URL");  
            }
            if ([string2 isURL]) { // **And here**
                NSLog (@"string2 is NOT URL"); 
            }
    }

What I'm doing wrong?

Upvotes: 0

Views: 87

Answers (1)

deanWombourne
deanWombourne

Reputation: 38475

isURL isn't the same as isUrl :)

You've called your method in your category isUrl but you're trying to use a method called isURL in your code.


Though you're better off letting iOS test if something is a URL or not -

-(BOOL)isURL {
    return nil != [NSURL URLWithString:self];
}

Upvotes: 3

Related Questions