我现在已经遇到这个错误好几次了,我不确定它是什么意思。我试着在网上寻找解决方案,但没有一个专门解决.type的问题。
这是我当前的错误:
private func setUpCache() {
let urlCache: URLCache = URLCache(memoryCapacity: MEMORY_CAPACITY, diskCapacity: DISK_CAPACITY, diskPath: "myDiskPath")
URLCache.shared = URLCache //<-Cannot assign value of type 'URLCache.type' to type 'URLCache'
}我在其他类型中也看到过这种错误。对于Int.type或string.type等类型的字符串,和Int意味着什么
发布于 2019-01-24 07:29:02
URLCache是类型(它是一个类)。URLCache.shared需要为它分配一个类的实例。但是您正在尝试分配类本身(它的类型是URLCache.type)。
你的错误代码应该是:
URLCache.shared = urlCache // your urlCache variable, not the URLCache type每当您看到关于SomeType.type的类似消息时,这意味着您正在尝试分配实际的类型,而不是该类型的实例。
let num: Int = Int // Cannot convert value of type 'Int.Type' to specified type 'Int'当然应该是:
let num: Int = 42 // Assign an actual Int value or variable of type Inthttps://stackoverflow.com/questions/54337219
复制相似问题