Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode = 0x0)

xcode
swift3

#1

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode = 0x0) Выдает ошибку, не могу понят.

import UIKit
import CoreData

class sporthallTableViewController: UITableViewController, NSFetchedResultsControllerDelegate {

var fetchResultsController: NSFetchedResultsController<Sporthall>!
var sporthalls: [Sporthall] = []
/*
    Sporthall(name: "Hammer", type: "Спорт залл", location: "Актобе, район Батыс 2, участок 11", image: "Hammer.jpg", isVisited: false),
    Sporthall(name: "ФОК", type: "Спорт залл", location: "Актобе, проспект Мира 40", image: "Fok.jpg", isVisited: false),
    Sporthall(name: "Нефтяник", type: "Спорт залл", location: "Актобе, улица Левой Мирзоян", image: "Neftyanik.png", isVisited: false),
    Sporthall(name: "Олимпийский резерв", type: "Спорт залл", location: "Актобе, улица Кунаева 2А", image: "OR.jpg", isVisited: false),
    Sporthall(name: "Ssang yong", type: "Спорт залл", location: "Актобе, проспект Санкибай батыр 253", image: "Ssangyong.jpg", isVisited: false),
    Sporthall(name: "Алихан", type: "Спорт залл", location: "Актобе, проспект Санкибай батыр 1В", image: "alikhan.jpg", isVisited: false),
    Sporthall(name: "АРГУ им. Жубанова", type: "Спорт залл", location: "Актобе, проспект Алия Молдагулова 34", image: "argu.jpg", isVisited: false),
    Sporthall(name: "АСМК", type: "Спорт залл", location: "Актобе, Аз-Наурыз 5", image: "asmk.jpeg", isVisited: false),
    Sporthall(name: "Авиатор", type: "Спорт залл", location: "Актобе, район Авиагородок 22", image: "aviator.png", isVisited: false)
*/

@IBAction func close (segue: UIStoryboardSegue) {
    
}

override func viewDidAppear(_ animated: Bool) {
    navigationController?.hidesBarsOnSwipe = true
}

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.backBarButtonItem = UIBarButtonItem (title: "", style: .plain, target: nil, action: nil)
    
    let fetchRequest: NSFetchRequest<Sporthall> = Sporthall.fetchRequest()
    let sortDescription = NSSortDescriptor(key: "name", ascending: true)
    fetchRequest.sortDescriptors = [sortDescription]
    
    if let context = (UIApplication.shared.delegate as? AppDelegate)?.coreDataStack.persistentContainer.viewContext {
        fetchResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
    }
    fetchResultsController?.delegate = self
    
    do {
        try fetchResultsController?.performFetch()
        sporthalls = (fetchResultsController?.fetchedObjects!)!
    } catch let error as NSError {
        print(error.localizedDescription)
    }
    
}

// MARK: - Fetch results controller delegate

func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
    tableView.beginUpdates()
}

func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
    
    switch type {
    case .insert: guard let indexPath = newIndexPath else { break }
        tableView.insertRows(at: [indexPath], with: .fade)
    case .delete: guard let indexPath = indexPath else { break }
        tableView.deleteRows(at: [indexPath], with: .fade)
    case .update: guard let indexPath = indexPath else { break }
        tableView.reloadRows(at: [indexPath], with: .fade)
    default:
        tableView.reloadData()
    }
    sporthalls = controller.fetchedObjects as! [Sporthall]
}

func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
    tableView.endUpdates()
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
    return sporthalls.count
}

//Ячейкага операция
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as!
        sporthallTableViewCell
    
    cell.thumbnaiImageView.image = UIImage(data: sporthalls[indexPath.row].image! as Data)
    cell.thumbnaiImageView.layer.cornerRadius = 32.5
    cell.thumbnaiImageView.clipsToBounds = true
    cell.nameLabel.text = sporthalls[indexPath.row].name
    cell.locationLabel.text = sporthalls[indexPath.row].location
    cell.typeLabel.text = sporthalls[indexPath.row].type
    
    cell.accessoryType = self.sporthalls[indexPath.row].isVisited ? .checkmark : .none
    
    return cell
}

/*
//Звондау, белгилеу, Alert
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    // first alert controller with action sheet style
    let ac = UIAlertController(title: nil, message: "Выберите действие", preferredStyle: .actionSheet)
    // first alert controller action
    let call = UIAlertAction(title: "Позвонить: +7(347)111-111\(indexPath.row)", style: .default) {
        (action: UIAlertAction) -> Void in
        // second alert controller inside first action
        let alertC = UIAlertController(title: nil, message: "Вызов не может совершен", preferredStyle: .alert)
        // second alert controller action
        let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
        // add action to second alert controller
        alertC.addAction(ok)
        // present second alert controler
        self.present(alertC, animated: true, completion: nil)
    }
    // second action
    let isVisitedTitle = self.sporthallIsVisited[indexPath.row] ? "Я не был здесь" : "Я был здесь"
    let isVisited = UIAlertAction(title: isVisitedTitle, style: .default) { (action) in
        let cell = tableView.cellForRow(at: indexPath)
        
        self.sporthallIsVisited[indexPath.row] = !self.sporthallIsVisited[indexPath.row]
        cell?.accessoryType = self.sporthallIsVisited[indexPath.row] ? .checkmark : .none
    }
    // third action
    let cancel = UIAlertAction(title: "Отмена", style: .cancel, handler: nil)
    // add all actions to first alert controller
    ac.addAction(call)
    ac.addAction(isVisited)
    ac.addAction(cancel)
    //present first alert controller
    present(ac, animated: true, completion: nil)
    
    tableView.deselectRow(at: indexPath, animated: true)
}
*/

/*
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete{
        self.sporthallNames.remove(at: indexPath.row)
        self.sporthallImages.remove(at: indexPath.row)
        self.sporthallIsVisited.remove(at: indexPath.row)
    }
    tableView.deleteRows(at: [indexPath], with: .fade)
}
*/

//Поделиться и удалить
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let share = UITableViewRowAction(style: .default, title: "Поделиться") {(action, indexPath) in
        let defaultText = "Я сейчас в " + self.sporthalls[indexPath.row].name!
        if let image = UIImage(data: self.sporthalls[indexPath.row].image! as Data){
            let activityController = UIActivityViewController(activityItems: [defaultText, image], applicationActivities: nil)
        self.present(activityController, animated: true, completion: nil)
        }
    }
    
    let delete = UITableViewRowAction(style: .default, title: "Удалить") {(action, indexPath) in
        self.sporthalls.remove(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .fade)
    }
    
    share.backgroundColor = #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)
    delete.backgroundColor = #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1)
    return [delete, share]
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "detailSegue"{
        if let indexPath = tableView.indexPathForSelectedRow{
            let dvc = segue.destination as! sporthallDetailViewController
            dvc.sporthall = self.sporthalls[indexPath.row]
        }
    }
}

#2

На это сообщение поступили жалобы от участников сообщества, поэтому оно временно скрыто.


#3

#4

https://drive.google.com/open?id=0B_QAkDf6BuRkbzhjZHNHTm1qQTA