views:

119

answers:

1

Here is the function where I get the compiler warning, I can't seem to figure out what is causing it. Any help is appreciated.

 -(void)displaySelector{
    //warning on the following line:
    InstanceSelectorViewController *controller = [[InstanceSelectorViewController alloc] initWithCreator:self];
    [self.navController pushViewController:controller animated:YES];
    [controller release];
}

Interface and implementation for the initWithCreator: method

-(InstanceSelectorViewController*)initWithCreator:(InstanceCreator*)creator;


-(InstanceSelectorViewController*)initWithCreator:(InstanceCreator*)crt{
    if (self = [self initWithNibName:@"InstanceSelectorViewController" bundle:nil]) {
        creator = crt;
    }
    return self;
}
+1  A: 

I'm guessing this is not the only class in your project that has an initWithCreator: method. In general, it is a bad idea to give static types to init methods. alloc returns id, so the compiler doesn't know the type of the object you're sending the init method to. If there's more than one choice, it will often guess wrong, and you'll get the warning you see.

Chuck
Thank you, this is exactly what the problem is. My fix based on your answer was to cast the type when I called initWithCreator: InstanceCreatorViewController *controller = [(InstanceCreatorViewController*)[InstanceCreatorViewController alloc] initWithCreator:self];
Alex Gosselin
that cast had an asterix in it, not sure where it went.
Alex Gosselin
@Alex Gosselin: Stack Overflow uses Markdown, which parses text between asterisks as emphasized. To have code formatted properly, place it between backticks. So it would be (backtick) `InstanceCreatorViewController *controller = [(InstanceCreatorViewController*)[InstanceCreatorViewController alloc] initWithCreator:self];` (backtick).
Chuck
Haha my friend you have all the answers.
Alex Gosselin