Seemingly-bogus error message when overriding a var

9 views
Skip to first unread message

Jens Alfke

unread,
Jul 10, 2015, 6:55:44 PM7/10/15
to swift-l...@googlegroups.com
I’ve got a variable with a public getter and internal setter, and I override it in a subclass but get an error complaining about the accessibility of the setter. This doesn’t make sense because the access control in the override is identical. If I take out “internal (set)”, to make the setter public, the error goes away; but I don’t want the setter to be public. What’s going on here?

(Xcode 7 beta 3)

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

public class OnlinePeer : Peer, NSNetServiceDelegate {
    public internal(set) override dynamic var online: Bool { … }
}

The error is:

Peer.swift:52:47: error: setter of overriding var must be as accessible as the declaration it overrides
    public internal(set) override dynamic var online: Bool
           ~~~~~~~~~~~~~~                     ^

           

Peer.swift:32:38: note: overridden declaration is here
    public internal(set) dynamic var online = false

—Jens
Reply all
Reply to author
Forward
0 new messages