初始化器
init(raw
init(rawValue:)
使用指定的原始值创建一个新实例。
必需的。
声明
init?(rawValue: Self.RawValue)
参数
rawValue
用于新实例的原始值。
详述
如果没有与指定原始值对应的类型的值,则此初始化程序返回 nil
。例如:
enum PaperSize: String {
case A4, A5, Letter, Legal
}
print(PaperSize(rawValue: "Legal"))
// Prints "Optional("PaperSize.Legal")"
print(PaperSize(rawValue: "Tabloid"))
// Prints "nil"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift RawRepresentable rawValue用法及代码示例
- Swift RawRepresentable用法及代码示例
- Swift RandomNumberGenerator用法及代码示例
- Swift RangeReplaceableCollection insert(_:at:)用法及代码示例
- Swift Range clamped(to:)用法及代码示例
- Swift RangeReplaceableCollection filter(_:)用法及代码示例
- Swift RangeReplaceableCollection removeFirst(_:)用法及代码示例
- Swift RangeReplaceableCollection用法及代码示例
- Swift RangeReplaceableCollection removeSubrange(_:)用法及代码示例
- Swift RangeReplaceableCollection replaceSubrange(_:with:)用法及代码示例
- Swift RangeReplaceableCollection removeFirst()用法及代码示例
- Swift RangeReplaceableCollection remove(at:)用法及代码示例
- Swift RandomAccessCollection subscript(_:)用法及代码示例
- Swift RangeExpression ~=(_:_:)用法及代码示例
- Swift Range overlaps(_:)用法及代码示例
- Swift RangeReplaceableCollection append(_:)用法及代码示例
- Swift RangeReplaceableCollection +=(_:_:)用法及代码示例
- Swift Range用法及代码示例
- Swift RandomAccessCollection indices用法及代码示例
- Swift Range endIndex用法及代码示例
- Swift RangeReplaceableCollection removeAll(where:)用法及代码示例
- Swift RandomAccessCollection index(_:offsetBy:)用法及代码示例
- Swift Range ~=(_:_:)用法及代码示例
- Swift RangeReplaceableCollection +(_:_:)用法及代码示例
- Swift RangeExpression relative(to:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 RawRepresentable init(rawValue:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。