简体   繁体   中英

Implicit Conversion from Objective-C Pointer to int * is Disallowed With ARC

I have an class DMGStatController which has a delegate of type DMGSecondaryStatViewController. I write

DMGStatController *controller = [[DMGStatController alloc] init]; 
controller.delegate = self;

It is this second line of code that is giving me the error "Implicit Conversion from Objective-C Pointer to int * is Disallowed With ARC". I don't know what the compiler is talking about... DMGStatController's property delegate is of type DMGSecondaryStatViewController, not int *. Any help would be much appreciated.

Also, here is where I declare the delegate.

#import <UIKit/UIKit.h>
#import "DMGSecondaryStatViewController.h"


@interface DMGStatDescriptionViewController : UIViewController{

}

@property(nonatomic , retain) DMGSecondaryStatViewController *delegate; 
@property(nonatomic , retain) NSString *finalStatChosen; 

@end

Make sure to #import "DMGStatController.h" , and that the header includes a @class DMGSecondaryStatController . You likely have a warning about the fact that it doesn't know what DMGSecondaryStatController is and that it's defaulting to int . Make sure that there are no warnings in your ObjC code. Most ObjC "warnings" are in fact errors.

I think you should change

#import "DMGSecondaryStatViewController.h"

to

@class DMGSecondaryStatViewController;

The lesson to learn: The compiler is right. The mental attitude "I don't know what the compiler is talking about" prevents you from finding the solution. You insist on your code being right, so you can't find the bug. The right attitude is "I made a mistake. What mistake did I make?"

If you turn on a few more warnings, you'll probably find that the compiler couldn't find a delegate method, therefore made some assumptions about what the parameters of the delegate method would be, and then complained because the conversion wasn't allowed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM