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
RedeemDx
V2EX  ›  iDev

有没有什么办法能规定或标记子类必须重载某一个方法

  •  
  •   RedeemDx · 2016-11-02 14:31:20 +08:00 · 3482 次点击
    这是一个创建于 2722 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如果没有重载,就有编译器警告之类的。

    现在的处理办法是在父类实现中抛出一个异常
    但这只会在运行时直接 crash
    而且如果之前不知道的话,在子类方法中有父类调用也会抛出这个异常....

    5 条回复    2016-11-03 01:12:53 +08:00
    Chrisplus
        1
    Chrisplus  
       2016-11-02 14:44:30 +08:00
    abstract ?
    wwwliangxin
        2
    wwwliangxin  
       2016-11-02 15:06:14 +08:00
    CommandZi
        3
    CommandZi  
       2016-11-02 15:09:28 +08:00
    protocol 的 @required 标记倒是可以在编辑器发出警告
    shoaly
        4
    shoaly  
       2016-11-02 15:37:10 +08:00
    把父类的方法 标记为 abstract, 或者直接把 必须继承的类 放到接口当中, 然后子类 implement
    RedeemDx
        5
    RedeemDx  
    OP
       2016-11-03 01:12:53 +08:00
    这个难道不是 iOS 开发节点?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1007 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:14 · PVG 06:14 · LAX 15:14 · JFK 18:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.