0

To support iOS 4.3 with ARC, I think the proper way is to use assign:

@property (assign, nonatomic) UIView *view;
@property (assign, nonatomic) MYNode *node;

Is that correct? I also see the following in Apple's doc for Transitioning to ARC:

For declared properties, you should use assign instead of weak; for variables you should use __unsafe_unretained instead of __weak.

However, if I use the current Xcode (4.4.1), changing a Single View app target to 4.3, and Ctrl-drag a UIButton to the .h file to create an outlet, the generated code is:

@property (unsafe_unretained, nonatomic) IBOutlet UIButton *foo;

Why the difference and which one should be used?

Jeremy L
  • 3,770
  • 6
  • 41
  • 62

2 Answers2

3

According to 4.1.1. Property declarations in the llvm documentation "assign" and "unsafe_unretained" are equivalent in a property declaration:

  • assign implies __unsafe_unretained ownership.
  • ...
  • unsafe_unretained implies __unsafe_unretained ownership.

ADDED: In the clang source code http://clang.llvm.org/doxygen/SemaObjCProperty_8cpp_source.html you find

00523   // 'unsafe_unretained' is alias for 'assign'.
00524   if (Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained)
00525     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • but could they both imply the same thing but still have differences? – Jeremy L Sep 08 '12 at 10:54
  • @JeremyL: I am sure that there is no difference. I assume that older Xcode versions did not understand `@property (unsafe_unretained, ...)`. I have some older versions so I can test that later if you are really interested. – Martin R Sep 08 '12 at 11:12
  • There is definitely no difference. – Catfish_Man Sep 08 '12 at 20:14
1

You've quoted excerpt from answer to the question "Which classes don’t support weak references?" — actually, I guess, the excerpt is meant to be applied only to the classes listed in the answer.

From what I've read before when I was studying ARC, there is no real difference between unsafe_unretained and assign.

ivanzoid
  • 5,952
  • 2
  • 34
  • 43
  • an answer said they are different? http://stackoverflow.com/questions/8397511/using-arc-lifetime-qualifier-assign-and-unsafe-unretained – Jeremy L Sep 08 '12 at 10:54
  • That answer is referring to `__unsafe_unretained`, not `unsafe_unretained`. – omz Sep 08 '12 at 11:24