简体   繁体   中英

New compiler warning in iOS 5 SDK about initializing with incompatible pointer types

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?

突出的一件事是,您将变量声明为drawTimebar但初始化并分配了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 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];

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