I’m new to Objective C (iOS) and I’m having a hard time figuring out this cryptic language.
I have no problem making a protocol (delegate) with one argument…
Person.h:
protocol PersonDetailsDelegate <NSObject>
@required
-(void) GetName:(NSString *) name;
@end
Person.m:
- (void) FireUpDelegate {
[self.delegate GetName: @"Michael"];
}
FirstViewController.m:
- (void) GetName: (NSString *) name {
NSLog(@"%@", name);
}
But I can’t figure out using two arguments….
Person.h:
@protocol PersonDetailsDelegate <NSObject>
@required
-(void) GetName:(NSString *) name; getAge:(int *) age;
@end
Person.m:
- (void) FireUpDelegate {
[self.delegate GetName: @"Michael"; getAge: 49];
}
FirstViewController.m:
- (void) GetName: (NSString *) name getAge: (int) age {
NSLog(@"%@ .. %i", name, age);
}
I get a quite some errors – any idea where it goes wrong?
Thanks a million!!
Mojo
You have one
;too many (aftername). It should be:The
;makes the compiler think the declaration of the method is finished, and that the method name isGetName:. If you remove the;, it is properly parsed asGetName:getAge:.EDIT: changed
(int *)to(int).