swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.27k stars 10.33k forks source link

[SR-1932] Strange behaviour and incorrect @IBAction / @IBOutlet linking #44541

Open iby opened 8 years ago

iby commented 8 years ago
Previous ID SR-1932
Radar None
Original Reporter @iby
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: f4c7cefc485f9bfba57b7871a3c9b3f0

Issue Description:

I have a view controller in my storyboard and instantiate it with @IBAction private func handleButtonAction(sender:NSButton). Often, in >80% cases, when I create my view controller using storyboard.instantiateControllerWithIdentifier(…), action handler handleButtonAction gets invoked on the wrong instance of my view controller when the button gets clicked. This is what code inside the handler produces:

belkadan commented 8 years ago

It's possible there is a problem with incremental rebuilds here—there are some known issues with private methods and properties that I really want to get to in Swift 3. Is this a project you can attach—if not here, then in Radar?

iby commented 8 years ago

Thats what I thought might be happening. Created a small project for this, the issue is reproducible 100%.

https://github.com/ianbytchek/SR-1932

Run, click buttons, the result is true. Terminate, run again, click buttons, the result is false. Clean build, repeat – true. Re-run – false.

iby commented 8 years ago

Workaround is to manually assign correct button target. Inside view controller:

iby commented 8 years ago

Hey @belkadan, this is really getting on my nerves. I heavily rely on interface builder and this happens in all places where I instantiate affected view controllers more than once. Is this a problem with Swift or the framework? Will reporting this on radar help at all or is this under control already? Wanna make sure whoever needs to know about this are informed.

iby commented 8 years ago

Also made an interesting observation, perhaps related? I have following code inside a similar handler as described above.

iby commented 5 years ago

Checked this again with the test project and everything seems to be working. @belkadan time to close this one!