sabari vasagan sabari vasagan - 1 year ago 163
Swift Question

exc bad instruction code exc i386 invop swift With NSArray

I faced "exc bad instruction code exc i386 invop" issue. I struggling to solve this issue. If any one know this ping me...

Issue

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("didselect")

if(tableView == self.tabledata){
print("Entered into tableview of listing")
let savearr : NSArray = UserDefaults.standard.object(forKey: "savedarray") as! NSArray

let addarr: NSArray = savearr.value(forKeyPath:"country") as! NSArray
let sumarr: NSArray = savearr.value(forKeyPath:"description") as! NSArray
let titarr: NSArray = savearr.value(forKeyPath:"title") as! NSArray


Then I Tried This code:

if let savearr : NSArray = UserDefaults.standard.object(forKey: "savedarray") as? NSArray
{
let addarr: NSArray = savearr.value(forKeyPath:"country") as! NSArray
let sumarr: NSArray = savearr.value(forKeyPath:"description") as! NSArray
let titarr: NSArray = savearr.value(forKeyPath:"title") as! NSArray
let MenuViewController = self.storyboard?.instantiateViewController(withIdentifier: "five") as! FiveStepsViewController

MenuViewController.writeTitleString = String(describing: titarr[indexPath.row])

MenuViewController.writeSummaryString = String(describing: sumarr[indexPath.row])

MenuViewController.writeAddressString = String(describing: addarr[indexPath.row])

//MenuViewController.writePriceString = String(describing: self.appDelegate.fivepricearray[indexPath.row])



self.present(MenuViewController, animated: true, completion: nil)
}
else {
print("Error Occured while listing")
}


Its always goes to else part..

Answer Source

Here I found my Solution

code:

if ( titarr.count > 0 ) {
       // rest of your code
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download