mattyd
mattyd

Reputation: 1683

Objective C category method not recognized in custom class "Cannot find interface declaration"

I want to use a custom method in a custom class in my viewcontroller

//Viewcontroller.h
#import "Class1.h"

//Class1.h
//#import "Class1+Category.h" // Deemed unnecessary in comments below.
@interface Class1: NSObject
-(void)doSomething;
@end

//Class1.m
#import "Class1.h"
@implementation Class1
-(void)doSomething{
  NSLog("In doSomething");
}
@end

Now I want a category method of Class1.

//Class1+Category1.h
#import "Class1.h"
@interface Class1  (Category1) // ERROR : Cannot find interface declaration
-(void)doAnotherThing;
@end

//Class1+Category1.m
#import "Class1+Category.h"
@implementation Class1 (Category1)
-(void)doAnotherThing{
  NSLog(@"Did Another thing");
}
@end

Finally - in my viewcontroller.m I see the doSomething method, but not the doAnother thing

 //viewcontroller.m
 Class1 *myClass1 = [[Class1 alloc]init];
 [Class1 doSomething]; //Works great!
 [Class1 doAnotherThing]; //Not recognized

I have added the -all_load to my target settings. I am out of ideas..do I use the @class? I get 'Cannot find interface declaration' error

Upvotes: 1

Views: 2228

Answers (1)

Taum
Taum

Reputation: 2551

Your class and category seems correct at first glance but your controller needs to import Class1+Category.h. Perhaps that's what you missed?

Upvotes: 6

Related Questions