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

为什么Xcode5在默认开启ARC的情况下,通过模版创建工程,默认生成的NSWindow的IBOutlet还是assign的呢?

  •  
  •   monkeycz · 2013-09-29 12:15:30 +08:00 · 3651 次点击
    这是一个创建于 3874 天前的主题,其中的信息可能已经有所发展或是发生改变。
    6 条回复    1970-01-01 08:00:00 +08:00
    zhigang1992
        1
    zhigang1992  
       2013-09-29 15:28:49 +08:00
    应该是weak吧
    monkeycz
        2
    monkeycz  
    OP
       2013-09-29 17:24:25 +08:00
    @zhigang1992 我现在的版本是Version 5.0 (5A1413),从 New -> Project -> OS X -> Cocoa Application 创建出来的工程,默认窗口的@property就是assign的。
    xesique
        3
    xesique  
       2013-09-29 18:01:38 +08:00   ❤️ 1
    monkeycz
        4
    monkeycz  
    OP
       2013-09-29 19:17:12 +08:00
    @xesique 明白了,多谢
    monkeycz
        5
    monkeycz  
    OP
       2013-09-29 19:26:29 +08:00
    @xesique 如果我错误的使用了weak,比如@property (weak) IBOutlet NSWindow *window;,编译器会报错么?
    我自己试了一下,可以编译通过。这个是由于编译器没有提示还是OS X 10.8的SDK下没有这个约定了呢?
    Apple的这篇文档(https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html)里只是说10.7下NSWindow等类不支持weak,没有说之后的系统如何。
    xesique
        6
    xesique  
       2013-09-29 22:37:06 +08:00
    编译器不会报错,如果对象不支持 weak 引用,程序在使用该引用时会崩溃[1][2]。苹果的文章确实只提到了 10.7 系统下面的情况,我估计 10.8 下这些对象可能已经支持了 weak 引用[3]。感觉做两个系统都兼容会比较麻烦……

    以上只是在网上搜集的资料,现在手边没有 Mac 无法测试,抱歉。

    [1] http://stackoverflow.com/questions/9146540/which-ios-classes-that-dont-support-zeroing-weak-references
    [2] http://stackoverflow.com/questions/12386340/if-arc-is-handled-by-the-compiler-why-is-weak-not-supported-on-ios-4-and-mac-os
    [3] http://stackoverflow.com/questions/10722238/nswindow-property-set-with-the-assign-attribute-instead-of-the-strong
    [4] http://stackoverflow.com/questions/11840728/lion-wont-run-app-built-with-mountain-lion
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1070 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 20:01 · PVG 04:01 · LAX 13:01 · JFK 16:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.