我这里有一个结构,当Xcode尝试编译它时会产生错误
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 {}}
}
我得到的错误是Type GATToIPPermissions does not conform to protocol RawRepresentable
。但是,我没有任何迹象表明为什么它不符合。
你们有没有发现这个问题?
答案 0 :(得分:0)
您编写的语法是您在protocol
中使用的语法。如果它在协议中,它将声明“符合类型必须实现名为init(rawValue:)
的初始化程序,并且具有GATToIPPermissions
类型的以下属性的getter:read
,write
,event
和all
“
但是你并不打算在protocol
中编写声明,而是想在struct
中编写实现,这就是看起来的样子:
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
}