我想添加一個函數,告訴我索引是否超出數組範圍。Extend CollectionType add indexOutOfRange function
CollectionType的startIndex和endIndex似乎是通用的,所以我試圖僅在索引類型爲Int時限制擴展。 此代碼不能編譯:
extension CollectionType where Index.Type is Int {
public func psoIndexOutOfRange(index: Index.Type) -> Bool{
return index < self.startIndex || index > self.endIndex
}
}
這可能嗎?什麼是添加這個的正確方法。
「psoIndexOutOfRange」?這是一種[匈牙利符號](https://en.wikipedia.org/wiki/Hungarian_notation)嗎? –