Reputation: 113
#import "PsychologistViewController.h"
#import "HappinessViewController.h"
@interface PsychologistViewController()
@property (nonatomic) int diagnosis;
@end
@implementation PsychologistViewController
@synthesize diagnosis = _diagnosis;
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ShowDiagnosis"]) {
[segue.destinationViewController setHappiness:self.diagnosis];
}
else if ([segue.identifier isEqualToString:@"Celebrity"]) {
[segue.destinationViewController setHappiness:100];
}
else if ([segue.identifier isEqualToString:@"Serious"]) {
[segue.destinationViewController setHappiness:20];
}
else if ([segue.identifier isEqualToString:@"TV Kook"]) {
[segue.destinationViewController setHappiness:50];
}
}
****- (void)setAndShowDiagnosis:(int)diagnosis****
{
self.diagnosis = diagnosis;
[self performSegueWithIdentifier:@"ShowDiagnosis" sender:self];
}
-(IBAction)flying
{
[self setAndShowDiagnosis:85];
}
-(IBAction)apple
{
[self setAndShowDiagnosis:100];
}
-(IBAction)dragons
{
[self setAndShowDiagnosis:20];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
@end
My question pertains to the - (void)setAndShowDiagnosis:(int)diagnosis
method. This method is undeclared anywhere as either public in any .h file and obviously it's not there privately either. My question is why the reason for this would be? It just shows its setter implementation but the actual method declaration appears nowhere. Any help to clarify this is appreciated. Oh and this is from an online lecture and everything compiles just fine and runs.
Upvotes: 0
Views: 1024
Reputation: 55604
You don't have to declare methods if you want them to private. There is no such thing as private methods in objective-c.
The difference between declaring a method in the header file, and a class extension at the top of implmentation file, is that if you don't declare it in the header, and you use the method from another class then the compiler will warn you that the method may not exist. But as long as you've implemented the method the application will not crash and the method will be called.
You could get away with not declaring any methods anywhere, but you will get lots of compiler warnings and it is harder to read later on, and harder for other people to understand your code. And there will be greater chance of you causing a crash because you miss spelt a method name,or some other trivial mistake.
Upvotes: 0
Reputation: 17732
Methods do not need to be declared, publicly, privately, or otherwise. Declaring a method in a .h file gives other users of the class knowledge of those methods. By not declaring it, you are hiding that method from the rest of the program that is using the class.
Upvotes: 1
Reputation: 3558
This method is undeclared anywhere as either public in any .h file and obviously it's not there privately either.
I think you answered your own question, its coming up undeclared, because it isn't being declared. Unless I am reading this wrong?
Upvotes: 0