V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
georgetso
V2EX  ›  iDev

这个例子代码中的警告如何处理?

  •  
  •   georgetso · 2015-07-21 22:51:12 +08:00 · 1788 次点击
    这是一个创建于 3217 天前的主题,其中的信息可能已经有所发展或是发生改变。
    地址: http://pan.baidu.com/s/1pJ7ReHH

    类似的情况有,

    ScrollView的定义
    @interface UIScrollView : UIView
    @property(nonatomic,assign) id<UIScrollViewDelegate> delegate;
    @end

    TableView的定义
    @interface UITableView : UIScrollView
    @property (nonatomic, assign) id <UITableViewDelegate> delegate;
    @end

    TableView Delegate的定义
    @protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>
    @end


    UIKit就是这样做的,我也这样做为什么被警告?
    3 条回复    2015-07-29 19:34:47 +08:00
    ashamp
        1
    ashamp  
       2015-07-22 00:12:14 +08:00
    关注.....
    a412739861
        2
    a412739861  
       2015-07-23 01:25:35 +08:00   ❤️ 1
    只是消除警告的话,改B的属性名称就呗。
    @property(nonatomic, weak) id<BProtocol> delegate1;
    ————————————————————————————————————————————
    http://stackoverflow.com/questions/9765033/how-to-properly-subclass-a-delegate-property-in-objective-c/14632135#14632135
    第一种模仿至UIKit的写法,应该是这个样子吧
    ————————————————————————————————————————————
    @class UITableView;
    @protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>
    // protocol~
    @interface UITableView : UIScrollView <NSCoding>
    @property (nonatomic, assign) id <UITableViewDelegate> delegate;

    所以应该上面的是漏写了吧,毕竟里面的东西有点乱糟糟的排布。>_< 不过他的两种方法,我都没成功。可能还漏了什么。
    ————————————————————————————————————————————
    但是第二种方法加的时候,警告不一样。
    //ClassB.h
    @property(nonatomic, weak) id<AProtocol,BProtocol> delegate;

    脑洞添加:
    //ClassB.m
    @dynamic delegate;
    警告消失了……

    所以是不是可能苹果隐藏了那部分能够消除警告的实现呢……
    ——————
    睡前看了这题,第一时间想的就是开头的原因,能解决警告,而且不仅仅是警告。不过这样不能达到override property,用起来的确很不舒服。
    Google关键词override property后想了点的成功。
    ————————
    距离我看到这个题目有一小时了,真是折腾自己。Google选手……hope helpful >_<睡去了。
    georgetso
        3
    georgetso  
    OP
       2015-07-29 19:34:47 +08:00
    @a412739861 @dynamic is just what I need
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2769 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:40 · PVG 15:40 · LAX 00:40 · JFK 03:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.