views:

3062

answers:

2

Hello,

I'm trying to get my head around Objective-C for the iPhone. My app is compiling and running just fine so far, but I'm getting a compiler warning that I cannot get rid of.

Header for one class: (snipped)

@interface PersonDetailViewController : UIViewController {
    NSDictionary *person;
}
@property (retain) NSDictionary *person;
@end

Implementation for this class: (also snipped)

#import "PersonDetailViewController.h"
@implementation PersonDetailViewController
@synthesize person;
@end

I'm creating an instance of PersonDetailViewController in PersonListViewController and calling:

#import "PersonListViewController.h"
#import "Person.h"
#import "PersonDetailViewController.h"

@implementation PersonListViewController
- (IBAction)myMethod:(id)sender {
    NSDictionary *person = [[Person alloc] initFromTestArray:[sender tag]];
    [personDetailViewController setPerson:person];
    [[personDetailViewController person] describe];
}
@end

And I'm then informed that:

warning: 'UIViewController' may not respond to '-setPerson' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)
warning: 'UIViewController' may not respond to '-person'

it does actually respond just fine, but I cannot figure out how to organise my headers so that the compiler would know what will respond...

I'm all out of Google... hope I've given enough info and somebody can help.

Thanks a heap!

+2  A: 

I'm a bit confused... Why would you do this:

NSDictionary *person = [[Person alloc] initFromTestArray:[sender tag]];

Your declaring person to be an NSDictionary, but are init'ing a Person class... Shouldn't it be

Person *person = [[Person alloc] initFromTestArray:[sender tag]];

edit I didn't notice the @property & synthesize, so you were correct there, my bad... the accept answer is what you were looking for!

micmoo
I agree with the first point, but `person` is a property which he declares in the header and synthesizes in the implementation.
Perspx
Ahhhh good point. I forgot about the @synthesize... i'll edit my post.
micmoo
+3  A: 

Apparently you have personDetailViewController declared as UIViewController? You can cast the controller explicitly:

[(PersonDetailViewController*)personDetailViewController setPerson:person];

But boy this is ugly. It would be better to simply declare the personDetailViewController as PersonDetailViewController in the PersonListViewController header. I hope I got it right, I got a bit dazed by all the long names :)

zoul
Aha! Yes. I was casting personDetailViewController as a generic UIViewController, hence the compiler didn't know to look for the synthesized setter and getter methods!As for micmoo's first point, that was me being daft and blind.It all looks a lot cleaner now and builds without errors! Many thanks!
sinissaar