의 프로토콜에 정의 된 첨자를 구현하는 동안이 1 VAR 2 첨자 다음과 같은 프로토콜 :오류 스위프트
protocol Universe{
var count: Int{get}
subscript(heroAtIndex index: Int)->SuperPowered {get}
subscript(villainAtIndex index: Int)->SuperPowered {get}
}
이 클래스에서이 프로토콜을 구현하기 위해 노력하고 있지만 :
class Marvel: Universe{
var _heroes = [
SuperPowered.heroWithFirstName("Peter", lastName: "Parker", alias: "Spiderman"),
SuperPowered.heroWithFirstName("Scott", lastName: "Summers", alias: "Cyclops"),
SuperPowered.heroWithFirstName("Ororo", lastName: "Monroe", alias: "Storm")]
var _villains = [
SuperPowered.villainWithFirstName("Victor", lastName: "Von Doom", alias: "Dr Doom"),
SuperPowered.villainWithFirstName("Erik", lastName: "Lehnsher", alias: "Magneto"),
SuperPowered.villainWithFirstName("Cain", lastName: "Marko", alias: "Juggernaut")]
// UNiverse protocol
var count : Int{
get{
return _heroes.count + _villains.count
}
}
subscript(heroAtIndex index: Int)->SuperPowered{
return _heroes[index]
}
}
을
las 라인 (아래 첨자)에 오류가 있습니다. 그것 불평한다
method 'subscript(heroAtIndex:)' has different argument names from those required by protocol 'Universe' ('subscript(villainAtIndex:)')
subscript(heroAtIndex index: Int)->SuperPowered{
^
나는 컴파일러가 무엇에 관해 말하고 있는지 전혀 모른다 : 이름은 동일하다. 그리고 나는 심지어 복사했고, 붙였다.
무슨 일 이니?
얘들 아, 아래 첨자를 구현하자마자 오류가 사라질 수 있으십니까? 오직 하나만 구현되는 한, 그 미친 오류로 실패합니다 ... – cfischer