最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[未解决]swift中嵌套枚举赋值时出错:Cannot assign value of type ContentType.Image to type ContentType

Uncategorized crifan 4374浏览 0评论

之前已经:

[已解决]swift枚举类型的继承

但是有个问题:

当去使用该枚举赋值的时候:

    func fromContentTypeOrSuffix(contentTypeOrSuffixStr:String) -> ContentType {
        var contentType = ContentType.Unknown
        if !contentTypeOrSuffixStr.isEmpty {
            let replacedStr = contentTypeOrSuffixStr.replace(“\\/”, to: “/”)
            print(“replacedStr=\(replacedStr)”) //image/jpeg
            let splitedStrArr = replacedStr.splitToStrArr(“/”)
            print(“splitedStrArr=\(splitedStrArr)”) //[“image”, “jpeg”]
            var secondStrOrSuffix = “”
            if splitedStrArr.count >= 2 {
                let firstStr = splitedStrArr[0]
                switch firstStr.lowercaseString {
                case “image”:
                    contentType = ContentType.Image
                    contentType = ContentType.Image.Unknown

出现不兼容:

Cannot assign value of type ‘ContentType.Image.Type’ to type ‘ContentType’

Cannot assign value of type ‘ContentType.Image’ to type ‘ContentType’

swift embedded enum  Cannot assign value of type

 swift nesting enum  Cannot assign value of type

搜:

swift nesting enum content type

The Nesting Rule · Issue #190 · realm/SwiftLint

Using a Nested Type in Swift — Coding Explorer Blog

Nested and Associated Enum Values Swift – Stack Overflow

Swift – Nested Enums default values – Stack Overflow

The Swift Programming Language (Swift 2.2): Nested Types

How do I access an enum from another class in Swift? – Stack Overflow

无法解决。

继续去:

swift enum subclass

 

转载请注明:在路上 » [未解决]swift中嵌套枚举赋值时出错:Cannot assign value of type ContentType.Image to type ContentType

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
87 queries in 0.194 seconds, using 22.14MB memory