Weird error overriding a property

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Weird error overriding a property

Jens Alfke
I’m getting an odd compile error in a pretty basic scenario: I’ve got a class hierarchy with a boolean “online” property that’s mutable but not externally settable. A subclass wants to add a ‘didSet’ observer to do something when the value changes:

public class Peer : NSObject {
    public internal(set) dynamic var online = false
}

public class OnlinePeer : Peer {

    public internal(set) override dynamic var online: Bool {  // ERROR!
        didSet {
            println("set online")
        }
    }
}

The error says “Setter of overriding var must be as accessible  as the declaration it overrides”, and the suggestion is to delete “internal (set)”. But this is backwards — the code is correct as written (I think), but removing “internal (set)” would make the setter public, which is different from the inherited access and not what I want.

(The didSet block doesn’t seem to be the source of the problem; I get the same error if I take it out.)

What’s going on here?

—Jens

PS: Xcode 6.3.2, iOS target

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/B8B12BA4-F00A-4556-889A-9504C60CC6C8%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.