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?


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
For more options, visit