devxoul / Then

✨ Super sweet syntactic sugar for Swift initializers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work with UIView subclasses after Xcode 7.3.1 update

fnc12 opened this issue · comments

...but works fine with CALayer, NSAttributesString subclasses

@fnc12, can you please attach the code?

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
        }
    }()

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

@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
        }
    }()

}

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

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.

@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.

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

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

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

Seems this has been fixed: apple/swift#2565