Accessor gives the wrong value in Swift 1.2/2.0 Release build only

前端 未结 1 350
我在风中等你
我在风中等你 2020-12-19 20:47

I found a very strange bug in my code that only happens in Release builds. It looks like a Swift bug to me, but let me know what you think.

import Foundation         


        
相关标签:
1条回答
  • 2020-12-19 20:54

    I think you've found a bug. A really interesting bug.

    And I have a workaround for you: make Attribute a class instead of a struct. It will still be a value class, so the overhead will be low. You will have to give it an initializer that does what the struct memberwise initializer does. You'll find that the whole problem goes away when you do this.

    EDIT: I thought of an even better workaround: Instead of making Attribute a class, make Level an @objc enum.

    EDIT: The OP reports that this bug is fixed in Swift 2.1.

    0 讨论(0)
提交回复
热议问题