let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(gesture:)))
calendarView.addGestureRecognizer(longPressGesture)
}
@objc func handleLongPress(gesture: UILongPressGestureRecognizer) {
guard gesture.state == .began else {return}
let position = gesture.location(in: collectionView)
if let indexPath = collectionView.indexPathForItem(at: position) {
guard let modalCalVC = self.storyboard?.instantiateViewController(identifier: "ModalCalViewController") as? ModalCalViewController else {
print("ModalCalViewController cannot be instantiated")
return
}
let value = true //Get the value you want to pass from `indexPath`
modalCalVC.passedValue = value
present(modalCalVC, animated: true, completion: nil)
} else {
print("Long press not on a cell")
}
}
I dont understand why it crashes I get Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file.swift, Line 10