I am creating a new file using Xcode’s navigation based application and I see that the .m file has these lines:
@interface RootViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end
Why is that declared on .m and not on .h itself?
wouldn’t it be easier to just put one line (this one below) on the header file?
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
I have seen this kind of approach in other codes. I am still learning Objective-C and I wonder why is that.
thanks.
By not putting it into the public interface of the class, you’re essentially making a method private (it doesn’t prevent people outside of your class from calling it if they really want to, but at least it causes a compiler warning).
is a class extension (= an anonymous category; a “normal” category would have a category name in between the
()). It purpose is to declare the private methods (otherwise you’d get a compiler warning if you’re trying to callconfigureCell:atIndexPath:in the.mfile prior to its implementation).You can read more about categories and class extensions in the developer documentation