对于文件的类型,想要实现main和sub的contentType的定义
enum MainContentType:String { case Unknown case Image case Audio case Video case Document } enum SubContentType:String { case Unknown } enum ImageType: SubContentType { case Gif case Icon case Jpeg //jpg, jpeg, jpe case Png case Tiff } class ContentType:NSObject, NSCoding { var mainType:MainContentType var subType:SubContentType var audioType:AudioType var videoType:VideoType var documentType:DocumentType |
但是会出错:
/Users/crifan/dev/dev_root/daryun/Workhub/sourcecode/WorkhubiOS/Workhub/Workhub/Resource.swift:23:17: Raw type ‘SubContentType’ is not convertible from any literal
swift enum subclass
ios – Swift – Subclass an Enum (or something to that effect) – Stack Overflow
How in Swift specify type constraint to be enum? – Stack Overflow
Advanced & Practical Enum usage in Swift
好像可以用:
嵌套的枚举
取代枚举的继承
从而实现我要的效果
enum ContentType:String { case Unknown enum Image:String { case Unknown case Gif case Icon case Jpeg //jpg, jpeg, jpe case Png case Tiff } enum Audio:String { case Unknown case Mid case Mp3 case Wav case Wma } enum Video:String { case Unknown case Asf case Avi case Mpeg //mp4, mpeg case Wmv // case Rmvb ??? // case Vob ??? } enum Document:String { case Unknown case Mpp case Pdf case Ppt case Txt case Vsd case Word case Xls case Html } } |
转载请注明:在路上 » [已解决]swift枚举类型的继承