Ios 在Segue中传递数据时,void _UIPerformResizeOfTextViewForTextContainer中的断言失败

Ios 在Segue中传递数据时,void _UIPerformResizeOfTextViewForTextContainer中的断言失败,ios,swift,Ios,Swift,所以在nextButtonPressed中,您可以看到I如果。媒体是一个视频(它是),我正在使用trimVideo功能和finishVideo的自定义完成处理程序创建一个带有修剪视频的缩略图,并执行segue本身 一切都执行无误,直到结束,所以我相信我发送的数据可能是错误的?如果是视频,可能与屏幕截图未设置有关 完全错误是 func trimVideo (sourceURL: URL, destinationURL: URL, trimPoints: TrimPoints, completion

所以在nextButtonPressed中,您可以看到I如果。媒体是一个视频(它是),我正在使用trimVideo功能和finishVideo的自定义完成处理程序创建一个带有修剪视频的缩略图,并执行segue本身

一切都执行无误,直到结束,所以我相信我发送的数据可能是错误的?如果是视频,可能与屏幕截图未设置有关

完全错误是

func trimVideo (sourceURL: URL, destinationURL: URL, trimPoints: TrimPoints, completion: @escaping () -> Void) {

        guard sourceURL.isFileURL else { return }
        guard destinationURL.isFileURL else { return }

        let options = [
            AVURLAssetPreferPreciseDurationAndTimingKey: true
        ]

        let asset = AVURLAsset(url: sourceURL, options: options)
        let preferredPreset = AVAssetExportPresetPassthrough

        if  verifyPresetForAsset(preset: preferredPreset, asset: asset) {

            let composition = AVMutableComposition()
            let videoCompTrack = composition.addMutableTrack(withMediaType: .video, preferredTrackID: CMPersistentTrackID())
            let audioCompTrack = composition.addMutableTrack(withMediaType: .audio, preferredTrackID: CMPersistentTrackID())

            guard let assetVideoTrack: AVAssetTrack = asset.tracks(withMediaType: .video).first else { return }
            guard let assetAudioTrack: AVAssetTrack = asset.tracks(withMediaType: .audio).first else { return }

            var accumulatedTime = kCMTimeZero
            for (startTimeForCurrentSlice, endTimeForCurrentSlice) in trimPoints {
                let durationOfCurrentSlice = CMTimeSubtract(endTimeForCurrentSlice, startTimeForCurrentSlice)
                let timeRangeForCurrentSlice = CMTimeRangeMake(startTimeForCurrentSlice, durationOfCurrentSlice)

                do {
                    try videoCompTrack!.insertTimeRange(timeRangeForCurrentSlice, of: assetVideoTrack, at: accumulatedTime)
                    try audioCompTrack!.insertTimeRange(timeRangeForCurrentSlice, of: assetAudioTrack, at: accumulatedTime)
                    accumulatedTime = CMTimeAdd(accumulatedTime, durationOfCurrentSlice)
                }
                catch let compError {
                    print("TrimVideo: error during composition: \(compError)")
                }
            }

            guard let exportSession = AVAssetExportSession(asset: composition, presetName: preferredPreset) else { return }

            exportSession.outputURL = destinationURL as URL
            exportSession.outputFileType = AVFileType.m4v
            exportSession.shouldOptimizeForNetworkUse = true

            removeFileAtURLIfExists(url: destinationURL as URL)

            exportSession.exportAsynchronously {
                completion()
            }
        }
        else {
            print("TrimVideo - Could not find a suitable export preset for the input video")
        }
    }     
@IBAction func nextButtonPressed(_ sender: Any) {

        if MyVariables.isScreenshot == true {
            //get image from current time
            print("screenshot")
            guard let currentTime = trimmerView.currentPlayerTime else {
                return
            }
            self.thumbnailImage = imageFromVideo(url: footageURL!, time: currentTime )
            self.screenshotOut = imageFromVideo(url: footageURL!, time: currentTime )
            self.performSegue(withIdentifier: "CreatePost_Segue", sender: nil)
        } else {
            print("video")
            let outputFileName = NSUUID().uuidString
            let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
            self.videoURL = URL(fileURLWithPath: outputFilePath)
            trimVideo(sourceURL: self.footageURL!, destinationURL: self.videoURL!, trimPoints: [(trimmerView.startTime!,trimmerView.endTime!)], completion: self.finishVideo)

        }
    }
    func finishVideo() -> Void {
            guard let VideoURL = self.videoURL else { return }
            self.thumbnailImage = setThumbnailFrom(path: VideoURL)
            print("got to segue") //This does print successfully so something is happening in the segue... 
            self.performSegue(withIdentifier: "CreatePost_Segue", sender: nil)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?){
        if segue.identifier == "CreatePost_Segue" {
            let controller = segue.destination as! CreatePostViewController
            controller.thumbnailImage = self.thumbnailImage
            controller.videoURL = self.videoURL
            controller.screenshotOut = self.screenshotOut
        }
    }
***无效断言失败_UIPerformResizeOfTextViewForTextContainer(NSLayoutManager*,UIView*,NSTextContainer*,nsInteger)(,/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIFoundation/UIFoundation-546.2/UIFoundation/TextSystem/NSLayoutManager\u Private.m:1619

我用@aBilal17给出的在主线程上运行segue的建议修复了这个问题,如下所示:

*** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIFoundation/UIFoundation-546.2/UIFoundation/TextSystem/NSLayoutManager_Private.m:1619

你检查过这个了吗?尝试使用主线程
func finishVideo() -> Void {
        guard let VideoURL = self.videoURL else { return }
        self.thumbnailImage = setThumbnailFrom(path: VideoURL)
        print("got to segue")
        DispatchQueue.main.async {
            self.performSegue(withIdentifier: "CreatePost_Segue", sender: nil)
        }
    }