[英]Struct does not conform to RawRepresentable protocol?
I have a struct here, which generates errors when Xcode tries to compile it 我这里有一个结构,当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 {}}
}
The error I get is Type GATToIPPermissions does not conform to protocol RawRepresentable
. 我得到的错误是
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? 你们中有人可以发现问题吗?
That syntax you're written is what you would use within a protocol
. 您编写的语法就是在
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
" 如果在协议中,它将声明“符合类型必须实现一个称为
init(rawValue:)
的初始化程序,并且必须具有GATToIPPermissions
类型的以下属性的GATToIPPermissions
: read
, write
, event
和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: 但是,您的目的不是要在
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.