Ben
Ben

Reputation: 984

Why cannot add method in category extension in objective-c?

With given class TestViewController, if a method is added to its extension. But error will pop up, what is the reason?

Code:

@interface TestViewController (){
    -(void) testMethod;
}

Parse error: TestViewController.m:12:5: Type name requires a specifier or qualifier

How to add a method to extension class which extend a anonymous category? thanks

Upvotes: 0

Views: 39

Answers (1)

Willeke
Willeke

Reputation: 15589

Remove the {}. ivars are declared inside {}, methods are declared outside the {}.

Upvotes: 3

Related Questions