0
雖然嘗試獲取子陣列與當時給定的範圍這個錯誤。嘗試獲得子陣列與給定的範圍
Cannot subscript a value of type '[Info]' with an index of type 'CountableRange<Int>' .
我的代碼是
信息莫代爾
class Info : NSObject {
var type : Type = .Unknown
var data = ""
init() {
super.init()
}
}
數組聲明
var currentData : [Info] = []
雖然試圖驗證碼
let moreAnimals: [Info] = self.currentData[0..<5] //above error disply.
您需要爲您的信息類添加自定義下標。更多參考:https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Subscripts.html#//apple_ref/doc/uid/TP40014097-CH16-ID305 – KKRocks