문제

I am facing a warning on the below line

enter image description here

This warning has arise after changing below line

@interface BDSAppDelegate : UIResponder <UIApplicationDelegate>

to

@interface BDSAppDelegate : UIResponder <UIApplicationDelegate, UIScrollViewDelegate>

Here I just conform UIScrollViewDelegate and this warning arise. Every things work perfect but I can't understand how to remove this warning. Can any one explain why this coming and how to remove it. Thanks in advance.

도움이 되었습니까?

해결책

[[UIApplication sharedApplication] delegate] returns a id<UIApplicationDelegate> which must be cast to BDSAppDelegate in order to prevent the warning.

In other words, all BDSAppDelegate's are a id<UIApplicationDelegate> but that doesn't mean that all id<UIApplicationDelegate> are a BDSAppDelegate.

다른 팁

Instead of adding <UIScrollViewDelegate> to the public interface, you should add it to a class extension in the implementation file:

BDSAppDelegate.h (public interface):

...
@interface BDSAppDelegate : UIResponder <UIApplicationDelegate> 
...

BDSAppDelegate.m (implementation):

#import "BDSAppDelegate.h"

@interface BDSAppDelegate () <UIScrollViewDelegate>
@end

@implementation BDSAppDelegate
...
@end

That makes the declaration local to the implementation, and

BSDAppDelegate *mainDelegate = [[UIApplication sharedApplication] delegate];

works without a cast (and without warning).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top