实例方法" makePetMakeNoise()"和" feedPet()"都在一个叫做人类的课堂上。当我在makeNoise()[在makePetMakeNoise里面]的调用中放入一个整数时,我收到一个错误:输入' Pets'不符合协议' IntegerLiteralConvertible' 我不确定这意味着什么,无法在google上找到任何有助于我的情况。
另外,当我在feedPet()中调用eat()方法时,即使我没有告诉eat()接受一个参数,当我调用eat()时它会给我警告&#34 ;在调用"
中缺少参数#1的参数非常感谢任何帮助。我被卡住了。
func makePetMakeNoise(numberInput:Int) -> Int {
Pets.makeNoise(4) //Type 'Pets' does not conform to protocol 'IntegerLiteralConvertible'
return random()
}
func feedPet() { // eat() doesn't accept any parameters. Why does is say "missing argument
Pets.eat() // for parameter #1 in call"?
}
class Pets: Humans {
func makeNoise(number:Int) { //Here I created makeNoise() that accepts an Int
if (pet == "Dog") {
petNoise = "is barking"
} else if (pet == "Cat") {
petNoise = "says meow"
}
if (canMakeNoise == true) {
for var x = 0; x <= number; x++ {
println("\(petName) \(petNoise)")
}
} else if (canMakeNoise == false) {
println("\(petName) remains silent.")
}
}
func eat() {
println("\(petName) is eating.")
}
答案 0 :(得分:1)
makeNoise(number: Int)
和eat()
都是您的班级Pets
的实例方法。因此,为了调用这些方法,我们必须实例化该类的对象。
let dog = Pet()
dog.makeNoise(4)
dog.eat()