-1

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..

sabari vasagan
  • 404
  • 5
  • 18

3 Answers3

1

This type of issues arises generally when we try to forcefully unwrap the nil data. Recheck your keys. And try to follow as shown in below code snippet.

guard let savearr = UserDefaults.standard.object(forked: "savedArray") as? NSArray,
  let addarr = savearr.value(forKeyPath: "country") as? NSArray,
  let summer = savearr.value(forKeyPath: "description") as? NSArray,
  let titter = savearr.value(forKeyPath: "title") as? NSArray

  else { return nil }
Krishnarjun Banoth
  • 1,410
  • 1
  • 15
  • 30
1
 let MenuViewController = self.storyboard?.instantiateViewController(withIdentifier: "five") as! FiveStepsViewController   

  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    


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

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

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

    }
    else {
        print("Error Occured while listing")
    }

 self.present(MenuViewController, animated: true, completion: nil)
Krishnarjun Banoth
  • 1,410
  • 1
  • 15
  • 30
0

Here I found my Solution

code:

if ( titarr.count > 0 ) {
       // rest of your code
    }
sabari vasagan
  • 404
  • 5
  • 18