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()
}
}
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.
@DanielKaplan
I am looking for an answer to the TITLE (as is the OP), not the cause of the stack trace. The answer must explain what "partial apply for closure#1" means.
A bit of background (from here, for more deep in math):
So what's going on with?
sessionQueue.async { [unowned self] in
self.configureSession()
}
Here we have closure calls function directly, swift compiler recognises this and makes currying, ie. instead of call function of function, unwraps closure and injects into async
direct call of internal function, like
sessionQueue.async(execute: CapturePipeline.configureSession(self))
but to join this with source code debug info should preserve information about this simplification, so they mark it as partial apply for closure# (where N is just ordered number of existed closures in parent function).
And to fix that crash as said before the best is to remove that part from init
at all and call after creation completed. The worse, but depending on other code might be applicable, is to use [weak self]
.
backup
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With