I'm trying to retrieve the detailedText contained in a UITableView Cell (which is a phone number "String") and then Use it in a function that will make a phone call.
Problem:
My app keeps crashing with the error "fatal error: unexpectedly found nil while unwrapping an Optional value " even though there is a value inside the variable.
I'm sure that I'm doing something wrong with force unwrapping the optional
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
let getPhone = cell?.detailTextLabel?.text
if indexPath.section == 0 && indexPath.row == 0 {
if let phoneNumber = getPhone{
openPhoneApp(phoneNumber)
}
}
// Open Phone App
func openPhoneApp(phoneNum: String){
UIApplication.sharedApplication().openURL(NSURL(string: "tel:\(phoneNum)")!)
}