[英]'self' used in method call 'foo' before 'super.init' call
我正在使用來自github的開源項目: https : //github.com/barnaclejive/FaceTrigger
我無法解決子類中的此錯誤:
錯誤:調用“ super.init”之前在方法調用“ onBoth”中使用“ self”
class BrowDownEvaluator: BothEvaluator {
func onBoth(delegate: FaceTriggerDelegate, newBoth: Bool) {
delegate.onBrowDownDidChange?(browDown: newBoth)
if newBoth {
delegate.onBrowDown?()
}
}
func onLeft(delegate: FaceTriggerDelegate, newLeft: Bool) {
}
func onRight(delegate: FaceTriggerDelegate, newRight: Bool) {
}
init(threshold: Float) {
super.init(threshold: threshold, leftKey: .browDownLeft, rightKey: .browDownRight, onBoth: onBoth, onLeft: onLeft, onRight: onRight)
}
}
家長班:
class BothEvaluator: FaceTriggerEvaluatorProtocol {
private let threshold: Float
private let leftKey: ARFaceAnchor.BlendShapeLocation
private let rightKey: ARFaceAnchor.BlendShapeLocation
private var onBoth: (FaceTriggerDelegate, Bool) -> Void
private var onLeft: (FaceTriggerDelegate, Bool) -> Void
private var onRight: (FaceTriggerDelegate, Bool) -> Void
private var oldLeft = false
private var oldRight = false
private var oldBoth = false
init(threshold: Float,
leftKey: ARFaceAnchor.BlendShapeLocation ,
rightKey: ARFaceAnchor.BlendShapeLocation ,
onBoth: @escaping (FaceTriggerDelegate, Bool) -> Void,
onLeft: @escaping (FaceTriggerDelegate, Bool) -> Void,
onRight: @escaping (FaceTriggerDelegate, Bool) -> Void)
{
self.threshold = threshold
self.leftKey = leftKey
self.rightKey = rightKey
self.onBoth = onBoth
self.onLeft = onLeft
self.onRight = onRight
}
我了解我必須在這里初始化onBoth和其余方法,但是如何初始化方法? 我還在學習Swift。
即使在允許引用self.methodName
情況下,也不應將實例方法設置為實例屬性,這會導致引用循環。
一個簡單的解決方法是這樣的:
class BrowDownEvaluator: BothEvaluator {
static func onBoth(delegate: FaceTriggerDelegate, newBoth: Bool) {
delegate.onBrowDownDidChange?(browDown: newBoth)
if newBoth {
delegate.onBrowDown?()
}
}
static func onLeft(delegate: FaceTriggerDelegate, newLeft: Bool) {
}
static func onRight(delegate: FaceTriggerDelegate, newRight: Bool) {
}
init(threshold: Float) {
super.init(threshold: threshold, leftKey: .browDownLeft, rightKey: .browDownRight,
onBoth: BrowDownEvaluator.onBoth,
onLeft: BrowDownEvaluator.onLeft,
onRight: BrowDownEvaluator.onRight)
}
}
如果您想作為BrowDownEvaluator
的實例訪問self
,事情會變得更加復雜。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.