【发布时间】:2018-11-15 22:41:40
【问题描述】:
我正在将一些业务逻辑从 iOS 转移到 Kotlin,这个结构对我来说似乎很奇怪
// AttachmentType.h
typedef NS_ENUM(NSUInteger, AttachmentType) {
AttachmentType1 = 0,
AttachmentType2 = 1,
AttachmentType3 = 2
}
// PhotoType.swift
enum PhotoType {
case t1(AttachmentType1), t2(AttachmentType1), t3(AttachmentType1)
var attachmentType: AttachmentType {
switch self {
case .t1(let type):
return type
case .t3(let type):
return type
case .t3(let type):
return type
}
}
}
我在这里感到困惑的是 ivar attachmentType
这本质上是
AttachmentType类型的变量吗?这是否允许这两种类型的所有 9 种排列。例如:我可以实例化一个 PhotoType,它用 t1 表示 AttachmentType1,用 t2 表示 AttachmentType1,用 t3 表示 AttachmentType1,用 t1 表示 AttachmentType2 等等...
Kotlin 的等效结构是什么? 9 个密封类?
【问题讨论】:
标签: objective-c swift kotlin enums