iOS 5 SDK 中关于使用不兼容的指针类型进行初始化的新编译器警告

发布于 2024-12-11 15:17:06 字数 276 浏览 0 评论 0原文

该语句

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎言笑 2024-12-18 15:17:06

值得注意的一件事是,您将变量声明为drawTimebar,但初始化并分配了drawTimebarView

One thing that stands out is that you are declare the variable as drawTimebar but initializing and assigning a drawTimebarView.

北渚 2024-12-18 15:17:06

首先,类名应始终以大写字母开头,并且采用驼峰式命名。这有助于其他人阅读您的代码并帮助您跟踪实例与类。

其次,您声明 drawViewdrawTimeBar 的实例(大概这是一个类,所以它实际上应该是 DrawTimeBar

drawTimebar *drawView

但是,当您初始化指针时,您正在使用此位创建 drawTimeBarView 的实例(大概也是一个类,因此应该是 DrawTimeBarView)。

[drawTimebarView initWithFrame:drawTimebarView.frame];

警告让您知道你是不一致。我猜你真的想拥有

drawTimebarView *drawView = [drawTimebarView initWithFrame:drawTimebarView.frame];

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 of drawTimeBar (presumably this is a class, so it really should be DrawTimeBar) with this bit

drawTimebar *drawView

However, when you initialize the pointer, you are creating an instance of drawTimeBarView (presumably also a class, and hence should be DrawTimeBarView) with this bit

[drawTimebarView initWithFrame:drawTimebarView.frame];

The warning is letting you know that you are inconsistent. My guess is that you really mean to have

drawTimebarView *drawView = [drawTimebarView initWithFrame:drawTimebarView.frame];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文