问题
I am trying to make sense of this crash report but can not make sense, because the function "applySettings()" is not called from init() as is shown in the crash report. What is "partial apply for closure#1" in Swift?
Here is the desired code for init() function.
public override init()
{
super.init()
discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera, AVCaptureDevice.DeviceType.builtInDualCamera, AVCaptureDevice.DeviceType.builtInTelephotoCamera, AVCaptureDevice.DeviceType.builtInDualWideCamera,
AVCaptureDevice.DeviceType.builtInTripleCamera,
AVCaptureDevice.DeviceType.builtInUltraWideCamera], mediaType: AVMediaType.video, position: .unspecified)
detectLenses()
checkForDeviceAuthorization()
setZoomParams()
sessionQueue.async { [unowned self] in
self.configureSession()
}
}
回答1:
You cannot do async stuff in an init
. We are trying to return the initialized object; that is all you should be doing here. Everything else should happen in some subsequent configuration call when self
completely exists.
来源:https://stackoverflow.com/questions/62820455/what-is-partial-apply-for-closure1-in-swift