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

Masonry 中 MASViewConstraint 的 copy 实现问题

  •  
  •   xi_lin · Feb 21, 2017 · 3920 views
    This topic created in 3543 days ago, the information mentioned may be changed or developed.

    具体实现见 https://github.com/SnapKit/Masonry/blob/master/Masonry/MASViewConstraint.m#L68

    我想问一下为啥这个 copy 的实现中忽略了好几个属性值?比如secondViewAttribute。

    6 replies  •  2017-03-07 14:41:22 +08:00
    game3108
    game3108
    Feb 21, 2017
    1
    因为你要看他使用的地方。他唯一使用的地方是#171 函数里面的- (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation 循环遍历内容,这个时候对于 MASViewConstraint 对象它并没有 secondViewAttribute 。
    xi_lin
    xi_lin
    OP
    Feb 22, 2017
    2
    @game3108 但是这样用起来有点危险,我不看代码直接用 copy 就丢失信息了
    game3108
    game3108
    Feb 22, 2017
    3
    @xi_lin 。。。你是改它源代码了?。。。
    xi_lin
    xi_lin
    OP
    Feb 23, 2017
    4
    @game3108 没有啊,我只是之前用的时候声明成 copy 出坑了

    ```
    @property (nonatomic, copy) MASConstraint *constraint;
    ```
    panzhougeek
    panzhougeek
    Mar 6, 2017
    5
    copy? 为啥要声明成 copy 一般除了字符串 Block 之类的 其他的都不会用 copy
    xi_lin
    xi_lin
    OP
    Mar 7, 2017
    6
    @panzhougeek 我这应用场景里是没啥必要用 copy 。不过总有要用的时候,比如 Masonry 自己内部使用的那个例子。虽然目前用不上一些特定属性,但要用到的时候意识不动 copy 实现里丢属性值也是很蛋疼的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1514 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:14 · PVG 02:14 · LAX 10:14 · JFK 13:14
    ♥ Do have faith in what you're doing.