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

问一个Object-C的编码规范的小问题

  •  
  •   baikang · 2013-09-05 16:03:54 +08:00 · 2937 次点击
    这是一个创建于 3898 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近在读苹果的文档,Programming with Objective-C,看到Conventions这节里面写到:

    If a method includes an error pointer parameter to be set if an error occurred, this should be the last parameter to the method. If a method takes a block, the block parameter should be the last parameter in order to make any method invocations as readable as possible when specifying a block inline.

    想问一下如果一个method同时具有error 和 block类型的参数,哪个应该应该放在最后一个?
    6 条回复    1970-01-01 08:00:00 +08:00
    railgun
        1
    railgun  
       2013-09-05 16:10:45 +08:00
    我建议是block在后面,因为block可能是很长的代码块。等你看完这个代码块之后,再突然冒出个参数会很突兀
    xhacker
        2
    xhacker  
       2013-09-05 16:16:08 +08:00
    @railgun: 可以用 typedef 为每种 block 指定类型,这样就短多了。

    我习惯 error 放最后。
    railgun
        3
    railgun  
       2013-09-05 16:20:42 +08:00
    @xhacker 呃,可能我没表达清楚,我指的是调用方法时候定义的匿名block,那个会很长。
    baikang
        4
    baikang  
    OP
       2013-09-05 17:15:04 +08:00
    @railgun
    @xhacker

    明白了,谢谢
    tgfbeta
        5
    tgfbeta  
       2013-09-05 22:31:21 +08:00
    其实,楼主是不是想把error传给block做参数?特别是Continuation Passing Style的方法。
    也许实际上需要两个block。我见过这么多API,很少有同时传入block和传出error引用的。
    Hysteria
        6
    Hysteria  
       2013-09-05 23:48:09 +08:00
    @railgun 说的很对。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2923 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 15:34 · PVG 23:34 · LAX 08:34 · JFK 11:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.