我似乎在使用[foo]()样式语法实例化嵌套类类型的空数组时出现问题:
// Playground - noun: a place where people can play
class outsideClass {
}
class Wrapper {
class InsideClass {
}
}
var foo = [outsideClass]() // Works fine
// Invalid use of '()' to call a value of non-function type '[Wrapper.InsideClass.Type]'
var bar = [Wrapper.InsideClass]()
Run Code Online (Sandbox Code Playgroud)
这是我误解的东西 - 它是在我的咖啡之前,但我已经检查了发行说明,我认为你应该能够引用这样的嵌套类 - 或者是beta 7中的错误?
这可以作为一种解决方法:
var foobar: [Wrapper.InsideClass] = []
Run Code Online (Sandbox Code Playgroud) 我正在一所着名大学提供的在线iOS课程.我不明白为什么以下代码使用override它是合法的.
根据官方定义,我们使用override覆盖超类的方法.以下代码中的子类和超类在哪里?
什么被覆盖,什么?
Run Code Online (Sandbox Code Playgroud)public override var description: String { return "\(url.absoluteString) (aspect ratio = \(aspectRatio))" }
我在Swift 2.3中写了以下扩展:
extension CollectionType {
/// Returns the element at the specified index iff it is within bounds, otherwise nil.
subscript (safe index: Index) -> Generator.Element? {
return indices.contains(index) ? self[index] : nil
}
}
Run Code Online (Sandbox Code Playgroud)
但事实证明,Swift 3.0没有contains()功能.相反,它为我提供了以下语法:
indices.contains(where: { (<#Self.Indices.Iterator.Element#>) -> Bool in
<# code ??? what should it do??? #>
})
Run Code Online (Sandbox Code Playgroud)
问题是我不知道它在块内应该包含什么.请帮忙迁移它吗?