swift的struct变量在switch语句中不可用

时间:2019-03-03 16:45:42

标签: struct switch-statement swift4.2

我想在2个图像源之间切换。 我有以下结构:

struct AppConstants {

static var imageSource:String = "goral"

static var fixURL = URL(string: "https://picsum.photos/375/375/?random")

struct Domains {

    static let baseurl = "http://www.m.myapp2go.de/services/"

}...

在我的viewController中的以下代码中,我无法在switch语句中访问var“ AppConstants.fixURL”:

 switch AppConstants.imageSource { // is filled with a value of a picker
    case "goral":
         let randomInt = Int.random(in: 1...12)
         let AppConstants.fixURL = URL(string: "http://www.m.myapp2go.de/pics/\(randomInt)_goral_item.jpg")

    case "picsum":
         let randomInt = Int.random(in: 1...1080)
         let AppConstants.fixURL = URL(string: "https://picsum.photos/375/375/?\(randomInt)")

    default:
        print("other")
    }

带有错误消息:

  

没有上下文类型就无法解析对成员'fixURL'的引用   和   模式中缺少类型注释

0 个答案:

没有答案