为什么我会收到这两个错误?
“Class'viewController'没有初始值设定项”
和
“'CurrentState'无法构造,因为它无法访问 初始值设定”。
import UIKit
import Foundation
import AVFoundation
let minFramesForFilterToSettle = 10
enum CurrentState {
case statePaused
case stateSampling
}
class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
let session = AVCaptureSession()
var camera : AVCaptureDevice?
var validFrameCounter: Int = 0
var pulseDetector: PulseDetector
var filter: Filter
var currentState = CurrentState() // init error
override func viewDidLoad() {
super.viewDidLoad()
self.pulseDetector = PulseDetector()
self.filter = Filter()
// TO DO startCameraCapture() // call to un-used function. TO DO create function
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:1)
CurrentState
是一个枚举,所以
var currentState = CurrentState() // init error
应该是(例如)
var currentState = CurrentState.statePaused
和属性
var pulseDetector: PulseDetector
var filter: Filter
没有初始值。你可以改变它 (我不知道这些类型,因此我不能说哪个是正确的 初始化):
var pulseDetector = PulseDetector()
var filter = Filter()
或覆盖每个指定的初始化方法以进行分配 初始值,或者将它们声明为(可能隐式展开) 选配:
var pulseDetector: PulseDetector!
var filter: Filter!