SourceView and SourceRect is depreciated?

Viewed 507

I'm trying to fix all my warnings for my project, but I can't seem to figure out how to do this.

The warning I am given is:

'sourceView' was deprecated in iOS 13.0: renamed to 'UIContextMenuInteraction'

I have read the documentation here but i still cant figure out how to fix this warning?

Here is the code it is talking about:

extension CollectionsViewController: UIViewControllerPreviewingDelegate {
    
    func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
        
        let tableView = previewingContext.sourceView as! UITableView
        if let indexPath = tableView.indexPathForRow(at: location) {
            
            let cell  = tableView.cellForRow(at: indexPath) as! CollectionCell
            let touch = cell.convert(location, from: tableView)
            
            if let productResult = cell.productFor(touch) {
                previewingContext.sourceRect = tableView.convert(productResult.sourceRect, from: cell)
                return self.productDetailsViewControllerWith(productResult.model)
                
            } else if let collectionResult = cell.collectionFor(touch) {
                previewingContext.sourceRect = tableView.convert(collectionResult.sourceRect, from: cell)
                return self.productsViewControllerWith(collectionResult.model)
            }
        }
        return nil
    }
    
    func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
        self.navigationController!.show(viewControllerToCommit, sender: self)
    }
}


Any help would be greatly appreciated!

1 Answers

UIViewControllerPreviewingDelegate protocol changed as documented:

Deprecated UseUIContextMenuInteractionDelegate instead.

So you need to remove previewingContext delegate method rather than change its parameter sourceview etc. Instead of this method you need to pick from the new protocol UIContextMenuInteractionDelegate of its delegate methods as Apple indicated.

In other words your extension is totally outdated and you need to rewrite according to new protocol.

Related