xcode ARC 不允许从 Objective-C 指针到 int * 的隐式转换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12043024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Implicit Conversion from Objective-C Pointer to int * is Disallowed With ARC
提问by Monkeyanator
I have an class DMGStatController which has a delegate of type DMGSecondaryStatViewController. I write
我有一个 DMGStatController 类,它有一个 DMGSecondaryStatViewController 类型的委托。我写的
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.
正是这第二行代码给了我错误“ARC 不允许从 Objective-C 指针到 int * 的隐式转换”。我不知道编译器在说什么... DMGStatController 的属性委托是 DMGSecondaryStatViewController 类型,而不是 int *。任何帮助将非常感激。
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
回答by Rob Napier
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.
确保#import "DMGStatController.h"
,并且标题包含@class DMGSecondaryStatController
. 您可能会警告它不知道是什么DMGSecondaryStatController
并且默认为int
. 确保您的 ObjC 代码中没有警告。大多数 ObjC“警告”实际上是错误。
回答by Junfeng Li
I think you should change
我觉得你应该改变
#import "DMGSecondaryStatViewController.h"
#import "DMGSecondaryStatViewController.h"
to
到
@class DMGSecondaryStatViewController;
@class DMGSecondaryStatViewController;
回答by gnasher729
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.
如果再多开几个警告,你可能会发现编译器找不到委托方法,因此对委托方法的参数做了一些假设,然后抱怨因为不允许转换.