devxoul / Then

✨ Super sweet syntactic sugar for Swift initializers
MIT License
4.18k stars 290 forks source link

Doesn't work with UIView subclasses after Xcode 7.3.1 update #23

Closed fnc12 closed 7 years ago

fnc12 commented 8 years ago

...but works fine with CALayer, NSAttributesString subclasses

devxoul commented 8 years ago

@fnc12, can you please attach the code?

1amageek commented 8 years ago

Value of type 'UIImageView' has no member 'then'

    private(set) lazy var imageView: UIImageView = {
        return UIImageView(frame: .zero).then {
            $0.contentMode = .ScaleAspectFill
            $0.clipsToBounds = true
        }
    }()
devxoul commented 8 years ago

@fnc12, Which version of Then are you using? If it is lastest version, could you please make a new project and try again?

devxoul commented 8 years ago

@1amageek Did you import Then correctly?

import Then

class MyClass {

    private(set) lazy var imageView: UIImageView = {
        return UIImageView(frame: .zero).then {
            $0.contentMode = .ScaleAspectFill
            $0.clipsToBounds = true
        }
    }()

}
philipengberg commented 8 years ago

I can confirm that this no longer works as of Xcode 7.3.1

philipengberg commented 8 years ago

Turns out this destroys everything:

extension NSObject : Then {}

If you instead do this:

extension UIView : Then {}

it works fine ¯_(ツ)_/¯ - for views only, obviously. It requires you to add the extension to every topmost type below NSObject, where you want to use then.

devxoul commented 8 years ago

@philipengberg, That's odd. Because my project has no problem at all. Even if I made a new project. Have you tested with a new project?

I'll try to find a solution as soon as possible.

fnc12 commented 8 years ago

This is very odd. I have three actual projects right now and two of them show me error with my UIView subclasses but one of them compiles ok

devxoul commented 8 years ago

@fnc12, can you guess what the difference between the projects is?

irace commented 8 years ago

I opened a Swift bug for this: https://bugs.swift.org/browse/SR-1480

BasThomas commented 8 years ago

Seems this has been fixed: https://github.com/apple/swift/pull/2565