在你的代码中,configJsonData
没有前缀 self.
,这会导致编译器提示你需要显式使用 self
。为了修复这个问题,你需要在访问 configJsonData
时加上 weakSelf
的前缀,因为它是通过 [weak self]
捕获的。
以下是修改后的代码:
extension CameraViewController: PoseLandmarkerServiceLiveStreamDelegate {
func poseLandmarkerService(
_ poseLandmarkerService: PoseLandmarkerService,
didFinishDetection result: ResultBundle?,
error: Error?) {
DispatchQueue.main.async { [weak self] in
guard let weakSelf = self else { return }
weakSelf.inferenceResultDeliveryDelegate?.didPerformInference(result: result)
guard let poseLandmarkerResult = result?.poseLandmarkerResults.first as? PoseLandmarkerResult else { return }
let imageSize = weakSelf.cameraFeedService.videoResolution
let poseOverlays = OverlayView.poseOverlays(
fromMultiplePoseLandmarks: poseLandmarkerResult.landmarks,
inferredOnImageOfSize: imageSize,
ovelayViewSize: weakSelf.overlayView.bounds.size,
locatMinX: weakSelf.configJsonData?.LocationList.first?.RectPoint.first?.x ?? 0,
locatMaxX: weakSelf.configJsonData?.LocationList.first?.RectPoint.last?.x ?? 0,
locatMinY: weakSelf.configJsonData?.LocationList.first?.RectPoint.first?.y ?? 0,
imageContentMode: weakSelf.overlayView.imageContentMode,
andOrientation: UIImage.Orientation.from(
deviceOrientation: UIDevice.current.orientation))
weakSelf.overlayView.draw(poseOverlays: poseOverlays,
inBoundsOfContentImageOfSize: imageSize,
imageContentMode: weakSelf.cameraFeedService.videoGravity.contentMode)
}
}
}
修改要点:
- 将对
configJsonData
的访问改为使用weakSelf.configJsonData
。 - 确保其他属性和方法的调用保持一致,这样就不会出现相同的问题。
这样一来,所有的属性和方法调用都将以正确的方式捕获并避免潜在的问题。
内容由零声教学AI助手提供,问题来源于学员提问