Xcode 5 problem?

The main thread is not seeing the new method. might this be a Xcode 5 issue, or is there something I’m missing?
I’m getting the error: No visible @interface for ‘NSString’ declares the selector ‘vowelCount’

[code]// VowelCounting.h
// VowelCounter

#import <Foundation/Foundation.h>

@interface VowelCounting : NSString

-(int)vowelCount;

@end[/code]

[code]// VowelCounting.m
// VowelCounter

#import “VowelCounting.h”

@implementation VowelCounting

-(int)vowelCount
{
NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:@“aeiouyAEIOUY”];

NSUInteger count = [self length];
int sum = 0;
for (int i=0; i < count; i++) {
    unichar c = [self characterAtIndex:i];
    if ([charSet characterIsMember:c]) {
        sum++;
    }
}
return sum;

}
@end[/code]

[code]// main.m
// VowelCounter

#import <Foundation/Foundation.h>
#import “VowelCounting.h”

int main(int argc, const char * argv[])
{
@autoreleasepool {

    NSString *string = @"Hello world";
    NSLog(@"%@ has %d vowels", string, [string vowelCount]);
}
return 0;

}[/code]

Thanx -

In stead of defining a category, you have defined a subclass.

[quote][code]// VowelCounting.h
// VowelCounter

#import <Foundation/Foundation.h>

@interface VowelCounting : NSString

-(int)vowelCount;

@end[/code][/quote]
Subclassing NSString should be extremely rare.

You are invoking a method named vowelCount on a string object.

[quote][code]int main (int argc, const char * argv[])
{
@autoreleasepool {

    NSString *string = @"Hello world";
    NSLog(@"%@ has %d vowels", string, [string vowelCount]);
}
return 0;

}[/code][/quote]
But NSString objects don’t know how to respond to that method.

You simply created a NSString subclass, not a category. If you have another look at the part where it tells you how to create the NSString category (File/New/Cocoa Touch/Objective-C Category (not class)) then you should be fine.

Nick

Got it - thank you!

I’m using Xcode 8.3.3 and there no longer appears to be a Category option. Any suggestions to what option should be used instead?

UPDATE:
After exploring this, I found that you can still select Category but it is hidden now. The way I selected it was to create a new file, and on the pop-up window where you pick a new template, select Objective-C File and click Next. On the next screen, select Category in the File Type field.