This is what I have in my implementation file for one of my classes...
Code Setup #1
@interface MyViewController (PrivateMethods)
- (NSString *)myPrivateMethod;
@end
@implementation MyViewController
- (void)viewDidLoad
{
NSString *myString = [self myPrivateMethod];
NSLog(@"%@", myString);
}
- (NSString *)myPrivateMethod
{
return @"someString";
}
@end
With this code, everything works and it logs "someString".
But shouldn't my code look differently somehow? I actually am using that category by accident (I had copy/pasted something and didn't notice "PrivateMethods" was there; I meant to be using a class extension).
Shouldn't my code actually look like one of the following:
Code Setup #2
@interface MyViewController ()
- (NSString *)myPrivateMethod;
@end
@implementation MyViewController
....
Or:
Code Setup #3
@interface MyViewController (PrivateMethods)
- (NSString *)myPrivateMethod;
@end
@implementation MyViewController (PrivateMethods)
....
What are the nuances behind what is happening in this situation? How is Code Setup #1 different from Code Setup #2?
Edit: Question about Setup #3
What does setting it up like this accomplish? Would this even "work"?
@interface MyViewController (PrivateMethods)
- (NSString *)myPrivateMethod;
@end
@implementation MyViewController
- (void)viewDidLoad
{
NSString *myString = [self myPrivateMethod];
NSLog(@"%@", myString);
}
@end
@implementation MyViewController (PrivateMethods)
- (NSString *)myPrivateMethod
{
return @"someString";
}
@end