Vikings
Vikings

Reputation: 2527

iPhone Method Prototype

I've been setting up my method prototype in the class file, instead of the header file. I'm not sure if it really makes a difference, should I be using the header files.

Are there disadvantages or advantages to setting the prototypes this way?

#import "SettingsViewController.h"

@interface SettingsViewController()

    - (void)syncSettings;

@end

@implementation SettingsViewController

- (void)syncSettings
{
    // Code Here
}

// Other Methods

@end

Upvotes: 0

Views: 156

Answers (2)

Conrad Shultz
Conrad Shultz

Reputation: 8808

@Tommy is quite correct. It should be noted that the methods will be invisible, but an enterprising (read: dangerous) programmer can still use them. Objective-C has no notion of enforced private methods.

And FYI, the construct @interface MyClass () is called a class extension or class continuation. Correct terminology will be helpful if you want to ask additional questions later.

Upvotes: 1

Tommy
Tommy

Reputation: 100602

Anything you restrict to the .m won't be visible to other .m files. So as a general rule, it's advantageous to put into your .h only the interface features that you intend to publish — don't put methods that you intend to keep private in there and don't put instance variables in there.

There are no disadvantages to keeping implementation details above and beyond the public interface unpublished.

Upvotes: 2

Related Questions