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

你们用 Masonry 的时候 mas_makeConstraints block 内部用 weakSelf 和 strongSelf 变换吗?

  •  
  •   SeanChense · 2015-10-19 14:45:00 +08:00 · 5621 次点击
    这是一个创建于 3111 天前的主题,其中的信息可能已经有所发展或是发生改变。
    12 条回复    2015-10-20 19:38:22 +08:00
    simon4761
        1
    simon4761  
       2015-10-19 15:20:35 +08:00
    我用的时候并没有刻意用 weakSelf.在有些库里面有对 self 进行处理。。所以可以不用 weakSelf.不过不知道 masonry 里有没做处理。
    SeanChense
        2
    SeanChense  
    OP
       2015-10-19 16:16:07 +08:00
    @simon4761 一开始我都有做 weak strong dance ,今天看到了这个 issue https://github.com/SnapKit/Masonry/issues/251

    似乎是不需要的。
    jesse_luo
        3
    jesse_luo  
       2015-10-19 18:10:28 +08:00
    不需要吧
    SeanChense
        4
    SeanChense  
    OP
       2015-10-19 18:24:30 +08:00
    @jesse_luo 似乎很多人都这么做了
    zjmdp
        5
    zjmdp  
       2015-10-19 18:24:42 +08:00
    一直没用,用过 instruments 做过 profile ,没看到有泄露
    jesse_luo
        6
    jesse_luo  
       2015-10-19 19:16:06 +08:00   ❤️ 1
    @SeanChense self 没有 retain 这个 block
    loveuqian
        7
    loveuqian  
       2015-10-19 19:17:31 +08:00
    它示例代码里也没用 weak 啊
    mornlight
        8
    mornlight  
       2015-10-19 19:21:08 +08:00
    我从来没用过。。。
    jackisnotspirate
        9
    jackisnotspirate  
       2015-10-19 19:38:39 +08:00
    - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block {
    self.translatesAutoresizingMaskIntoConstraints = NO;
    MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
    block(constraintMaker);
    return [constraintMaker install];
    }
    PhilCai
        10
    PhilCai  
       2015-10-20 10:33:24 +08:00   ❤️ 1
    没有,因为那个 block 没有被当作属性 copy
    dorentus
        11
    dorentus  
       2015-10-20 11:49:26 +08:00   ❤️ 1
    不需要。

    它的 Swift 版, SnapKit ,对应的方法 snp_makeConstraints 把最后的 block 参数标记成了 @noescape ,即这个 block 的生存期不会超出这个方法的生存期,且不会被任意方 retain 或 copy 。
    hustlzp
        12
    hustlzp  
       2015-10-20 19:38:22 +08:00
    没有。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5095 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:44 · PVG 13:44 · LAX 22:44 · JFK 01:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.