Details
-
Type:
Bug
-
Status: Resolved
-
Priority:
Medium
-
Resolution: Duplicate
-
Component/s: Compiler
-
Labels:None
-
Environment:
Xcode 8.3.2
Description
This is legal in an instance property declaration:
let listen : UIBarButtonItem = {
let b = UIBarButtonItem(barButtonSystemItem: .play, target: self, action: #selector(doListen))
return b
}()
It shouldn't be. There is no `self` at this point. The code compiles but it isn't going to work, so it shouldn't compile at all.
I see a lot of people on Stack Overflow get caught by this sort of thing, but this is the first time I've made the same mistake myself. The usual context is in configuring a Timer.
Attachments
Issue Links
- duplicates
-
SR-4559 'self' in property initial value expression refers to class (?)
-
- Open
-