Swifterswift: open instead of public

Created on 13 Jun 2017  路  16Comments  路  Source: SwifterSwift/SwifterSwift

error when using this lib with a custom uicontrol.
complaining about Overriding non-open var outside defining module.

Most helpful comment

i guess a lot of UIKit would have to be open.

All 16 comments

@mateo666 Can you give some more information so that we can assist you? Possibly, the piece of code that is creating this issue? Thank you.

was using the view extension. following var

@IBInspectable
    /// SwifterSwift: Corner radius of view; also inspectable from Storyboard.
    public var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.masksToBounds = true
            layer.cornerRadius = abs(CGFloat(Int(newValue * 100)) / 100)
        }
    }

my UIControl also defines a public var cornerRadius: CGFloat

@mateo666 thank you for raising this issue

i guess a lot of UIKit would have to be open.

@omaralbeik What do you think? If we change access control to open opposed to public then users will be able to change the behavior of SwifterSwift extensions when subclassing.

Considering our design of SwifterSwift extensions not being dependent on the implementation of other SwifterSwift extensions -- I would feel comfortable changing access control to open.

I'm not sure what the drawbacks are to this -- if there are any.

Thinking about this more, I think the public access level is a significant limitation. It makes no sense to not allow users to override methods and properties on something as broad as UIKit components.

I agree with you guys, I changed it to Poll, please vote

Community voted to add this feature

@SD10 Could you please replace all public with open

And by community I mean @SD10, @pvtmert and I ;)

Sure, will do 馃憤

Looks like we cannot use open inside of a public extension because it is a less restrictive form of access control. Extensions cannot have open access control, therefore, this doesn't look possible.

@SD10 I meant change everything to open including extension and inner unites, if the extension is open and all inner functions are open, why can't we do this?

@omaralbeik Extensions cannot have open access control modifiers. Therefore, this doesn't look possible.

@mateo666 For future reference, if you need to subclass a SwifterSwift extended type, you will have to choose method names that don't conflict with the SwifterSwift names.

Example:

cornerRadius // SwifterSwift
_cornerRadius // Your Module

I can't think of any other way to achieve this. We would have to move the extensions on classes into a subclass to allow them to be overridden -- which just doesn't fit the vision of this project.

Thank you @SD10!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pawurb picture pawurb  路  3Comments

fanglinwei picture fanglinwei  路  5Comments

fanglinwei picture fanglinwei  路  3Comments

pawurb picture pawurb  路  3Comments

omaralbeik picture omaralbeik  路  3Comments