1

When I control-drag outlet from xib, I got unsafe_unretained property by default. I'm using Xcode 9.1. The following code is what it looks like.

@property (unsafe_unretained, nonatomic) IBOutlet UILabel *shIndexLabel;
Cœur
  • 37,241
  • 25
  • 195
  • 267
Lumialxk
  • 6,239
  • 6
  • 24
  • 47

2 Answers2

1

__unsafe_unretained specifies a reference that does not keep the referenced object alive and is not set to nil when there are no strong references to the object. If the object it references is deallocated, the pointer is left dangling.

Above excerpt from Apple docs. So answering your question WHY?

It is not possible for the Swift compiler to know if these references are really intended to be strong (+1) or unretained (+0)

This change involved with respect to the swift compiler. They made __unsafe_unretained by default.

Sivajee Battina
  • 4,124
  • 2
  • 22
  • 45
  • Thanks for your professional answer! One more question, did `weak` do the same thing to swift compiler? – Lumialxk Nov 17 '17 at 06:58
  • Please accept this answer in case it clarified your doubt. So that it will be useful to some other person having the same doubt as you. – Sivajee Battina Nov 23 '17 at 11:36
  • Swift compiler knows weak(+0) at least. Apple changed it to __unsafe_unretained to indicate outlets will be left dangling. I don't understand this. – Lumialxk Nov 24 '17 at 01:41
1

Actually, it's a bug of Xcode. It seems unsafe_unretained will appear when project didn't complete indexing. So we should change it to weak manually.

Lumialxk
  • 6,239
  • 6
  • 24
  • 47