Struct does not conform to RawRepresentable protocol?

2.2k views Asked by At

I have a struct here, which generates errors when Xcode tries to compile it

public struct GATToIPPermissions : OptionSet {

    public init(rawValue: UInt)


    public static var read: GATToIPPermissions { get {}}

    public static var write: GATToIPPermissions { get {}}

    public static var event: GATToIPPermissions { get {}}

    public static var all: GATToIPPermissions { get {}}
}

The error I get is Type GATToIPPermissions does not conform to protocol RawRepresentable. However, I dont get any indication as to why it doesn't conform.

Can any of you spot the problem?

1

There are 1 answers

0
Alexander On

That syntax you're written is what you would use within a protocol. If it were in a protocol, it would declare "Conforming types must implement an initializer called init(rawValue:), and have getters for the following properties of type GATToIPPermissions: read, write, event, and all"

But you're not aiming to write declarations in a protocol, you're looking to write implementations in a struct, and here is how that would look:

public struct GATToIPPermissions : OptionSet {

    public init(rawValue: UInt) {
        //initialize self with `rawValue`
    }


    public static let read = GATToIPPermissions() //set me to the right value
    public static let write = GATToIPPermissions() //set me to the right value
    public static let event = GATToIPPermissions() //set me to the right value
    public static let all = GATToIPPermissions() //set me to the right value
}