0

I've noticed that if I remove the action method declaration in the header file of a view controller, the action still works as it is implemented in the implementation file. Why is it necessary to define a method declaration in the header file of a view controller?

Thanks

Imran Azad
  • 1,384
  • 1
  • 21
  • 36

1 Answers1

2

so that you dont receive warnings from the compiler that the selector is not found,

In ARC environment, removing the function declaration from the .h file will result in error and not warning ( No visible @interface for 'YourClass' declares the selector 'YourMethod')

However if you connect your method from xib (action for a UIButton for example), then you can remove the function from the interface file and you will not receive any error or warning

Please note that Objective-c has no pure private methods.

Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56
  • Thanks for the response. I'm using Automatic Reference Counting in my application and I'm not seeing any errors. Is that what you mean by "ARC environment"? – Imran Azad Jun 24 '12 at 13:09
  • You should get an error when compiling, for example "No visible @interface for 'ViewController' declares the selector 'some_function'" – Omar Abdelhafith Jun 24 '12 at 13:11
  • @ImranAzad please read updated answer also read more from http://stackoverflow.com/questions/2158660/why-doesnt-objective-c-support-private-methods – Omar Abdelhafith Jun 24 '12 at 13:15