执行操作时迅速出错

时间:2018-07-15 16:22:46

标签: swift xcode if-statement swift3

  

线程1:EXC_BAD_ACCESS(代码= 2,地址= 0x7ffee3387ff8)

如果有错误,可以纠正吗?我认为问题来自else if语句{} <是否有任何人可以解决它,并告诉我之前发布的代码中的问题在哪里,以及解决该问题的方法我不知道是否有些可以帮助我吗?

func fetchAndUpdateTableView(){
    if catagory == "Tools" {
        if let url = urlCoreData{
            switch (url) {
        case "All_m0":
            let shit = All_m0()
            coreVariables.results_All_M0 = shit.fetchProduct()!
            break
        case "Screw_drive":
            let  screwd = Screw_drive()
            coreVariables.results_Screw_Drive = screwd.fetchProduct()!
            break
        case "Wrench_m":
            let Wrenchm = Wrench_m()
            coreVariables.results_Wrench_M = Wrenchm.fetchProduct()!
            break
        default:
            break
        }
        }

        else if catagory == "Water Pressure"{
            if let url = urlCoreData{
                switch (url) {
                case "All_m1":
                    let All1 = All_m1()
                    coreVariables.results_All_M1 = All1.fetchProduct()!
                    break
                default:
                    break
                }

        }



        else if catagory == "Garden Equipments"{

            if let url = urlCoreData{
                switch (url) {
                case "All_m2":
                    let All2 = All_m2()
                    coreVariables.results_All_M2 = All2.fetchProduct()!
                    break
                default:
                    break


        }
            }


        }
   tableView.reloadData()
    }

}
}

//MARK: get and parse JSON

func processJsonData(resource : String) {
    let path = Bundle.main.path(forResource: resource, ofType: "json")
    do {
        let data = try Data(contentsOf: URL(fileURLWithPath: path!), options: .alwaysMapped)
        do{
            let object = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments)
            if let dictionary = object as? NSArray {
                fetch_Store_Functions.readJSONObject(object: dictionary, catagory: catagory, urlCoreData: urlCoreData)
            }
        } catch {
            // Handle Error
        }
    } catch let error {
        print(error.localizedDescription)
    }
}

func loadFunction(){
    if catagory == "Tools" {
        if let url = urlCoreData{
            switch (url) {
        case "All_m0":
          //  self.fetchAndUpdateTableView()
            if coreVariables.results_All_M0.count == 0{
                self.processJsonData(resource: selectedCatagory)
            }else{
                self.fetchAndUpdateTableView()
                tableView.reloadData()
            }
            break
        case "Screw_drive":
        //self.fetchAndUpdateTableView()
            if coreVariables.results_Screw_Drive.count == 0{
                self.processJsonData(resource: selectedCatagory)
                tableView.reloadData()
            }else{
                self.fetchAndUpdateTableView()
                tableView.reloadData()
            }
            break
        case "Wrench_m":
           // self.fetchAndUpdateTableView()
            if coreVariables.results_Wrench_M.count == 0{
                self.processJsonData(resource: selectedCatagory)
                tableView.reloadData()
            }else{
                self.fetchAndUpdateTableView()
                tableView.reloadData()
            }
            break
        default:
            break
        }
        }
    }else if catagory == "Water Pressure"{
            if let url = urlCoreData{
                switch (url) {
            case "All_m1":
                self.fetchAndUpdateTableView()
                if coreVariables.results_All_M1.count == 0{
                    self.processJsonData(resource: selectedCatagory)
                    tableView.reloadData()
                }else{
                    self.fetchAndUpdateTableView()
                    tableView.reloadData()
                }
                break
                default:
                    break
            }
        }
    }else if catagory == "Garden Equipments"{
        if let url = urlCoreData{
            switch (url) {
            case "All_m2":
                //  self.fetchAndUpdateTableView()
                if coreVariables.results_All_M2.count == 0{
                    self.processJsonData(resource: selectedCatagory)
                }else{
                    self.fetchAndUpdateTableView()
                    tableView.reloadData()
                }
                break
            default:
                break


        }
    }

    }
}

1 个答案:

答案 0 :(得分:0)

您需要在方案中放入“僵尸对象”,然后进入配置文件工具“僵尸”并运行该应用程序,看看它是否能像这样捕获它。

当已将内存分配给变量,然后释放该错误,然后另一个进程尝试使用该变量时,将发生此错误。