Adam Adam - 8 months ago 67
Swift Question

Swift Error "static member cannot be used on instance of type"

I want to overload the operator for my struct but I get the message "static member 'rating' cannot be used on instance of type 'GlobalSettings'".
I already read couple answers to this error but the solutions there don't help me at all. How can I solve this problem?

struct GlobalSettings{
static var rating = false

func ==(l: GlobalSettings, r: GlobalSettings) -> Bool {
if l.rating == r.rating {
return true
return false

Answer Source

It is an obvious error. Static member can not be accessed with Instance variables like l and r.

Static members must be accessed through the type (class/struct/enum) name like:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download