iPhone – Why is it in .m declared some methods instead .h?

I am using Xcode’s navigation-based application to create a new file, and I see that the .m file contains the following lines:

@interface RootViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end

Why declare on .m Instead of declaring it on the .h itself?

Will it be easier to put one line (the one below) on the header file?

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;

I have seen this in other codes Method. I’m still learning Objective-C, I want to know why this happens.

Thank you.

By not putting it in the public interface of the class, you are actually a private method (it won’t stop people outside your class if they really want to call it, but at least it will cause Compiler warning).

@interface RootViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end

is a class extension (=anonymous category; the “normal” category has category names between (). Its purpose is to declare private methods (otherwise, if you try before implementing Call configureCell:atIndexPath: in the .m file, and you will receive a compiler warning).

You can read more about categories and class extensions in the developer documentation

I am using Xcode’s navigation-based application to create a new file, and I see that the .m file contains the following lines:

 @interface RootViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end

Why is it declared on .m but not on. H itself?

Will it be easier to put a line (the following line) in the header file?

- (void)configureCell: (UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath; 

I have seen this method in other code. I am still learning Objective-C, I want to know why this is the case.

Thank you.

By not putting it into the public interface of the class, you are actually a private method (it won’t stop people outside your class if they really want to call it, But at least it will cause the compiler to warn).

@interface RootViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:( NSIndexPath *)indexPath;
@end

is a class extension (=anonymous category; the “normal” category has category names between (). Its purpose is to declare private methods (otherwise, if If you try to call configureCell:atIndexPath: in the .m file before implementation, you will receive a compiler warning).

You can read more about categories and class extensions in the developer documentation

p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1050 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.