【发布时间】:2018-04-10 05:05:40
【问题描述】:
我是 swift 新手,正在使用 Swift 4.0 。我正在尝试为我的类创建一个构造函数,该构造函数接受 1 个字符串参数并且在使其工作时遇到问题。我也得到错误
调用中的参数标签不正确(具有“类型:”,预期为“编码器:”)
我一直在移动东西,但它不起作用。我想在下面更改我的子类,以便每当我想使用该类时,都需要以下签名 CustomAVPLayerC(type: "string") 。这是我第一次这样做,因为我通常使用函数。
这是我的代码
import UIKit
import AVKit
class CustomAVPLayerC: AVPlayerViewController {
var ControllerType: String
init(type: String) {
self.ControllerType = type
// perform some initialization here
super.init(type: "")
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if player?.isMuted == true {
player?.isMuted = false
//showsPlaybackControls = false
} else {
player?.isMuted = true
}
}
}
【问题讨论】:
-
哪一行产生了错误?
-
与您的问题无关,但变量名称应以小写字母开头。将
ControllerType更改为controllerType。 -
会改变变量名和super.init(type: "") 抛出错误
-
把
super.init(type: "")改成super.init(),这是来自BaseClass,你的基类没有super.init(type: "")。