iOS 5 SDK 中关于使用不兼容的指针类型进行初始化的新编译器警告
该语句
drawTimebar *drawView = [drawTimebarView initWithFrame:drawTimebarView.frame];
在 iOS 4 中运行得很好,但在 iOS 5 SDK 中会发出警告:
使用“UIView *”类型的表达式初始化“drawTimebar *”时不兼容的指针类型
为什么会发生这种变化,我可以采取什么措施来解决它?
This statement
drawTimebar *drawView = [drawTimebarView initWithFrame:drawTimebarView.frame];
was working just fine in iOS 4, but with the iOS 5 SDK gives a warning:
Incompatible pointer types initializing 'drawTimebar *' with an expression of type 'UIView *'
Why has this changed, and what can I do to solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
值得注意的一件事是,您将变量声明为
drawTimebar
,但初始化并分配了drawTimebarView
。One thing that stands out is that you are declare the variable as
drawTimebar
but initializing and assigning adrawTimebarView
.首先,类名应始终以大写字母开头,并且采用驼峰式命名。这有助于其他人阅读您的代码并帮助您跟踪实例与类。
其次,您声明
drawView
是drawTimeBar
的实例(大概这是一个类,所以它实际上应该是DrawTimeBar
)但是,当您初始化指针时,您正在使用此位创建
drawTimeBarView
的实例(大概也是一个类,因此应该是DrawTimeBarView
)。警告让您知道你是不一致。我猜你真的想拥有
First, Class names should always begin with a capital latter and be CamelCased. This helps others read your code and helps you keep track of instances versus classes.
Second, you are declaring that
drawView
is an instance ofdrawTimeBar
(presumably this is a class, so it really should beDrawTimeBar
) with this bitHowever, when you initialize the pointer, you are creating an instance of
drawTimeBarView
(presumably also a class, and hence should beDrawTimeBarView
) with this bitThe warning is letting you know that you are inconsistent. My guess is that you really mean to have