ios - 错误 - 线程 1 exc_bad_instruction(代码=exc_1386_invop 子代码=0x0)

标签 ios swift

我对这段代码有疑问-

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func get(){
    let url = NSURL(string: "http://www..php")
    let data = NSData(contentsOfURL: url!)
    values = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as!NSArray

    tableView.reloadData()
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return values.count;
}

这个错误 线程 1 exc_bad_instruction (code=exc_1386_invop subcode=0x0)

最佳答案

试试这个-

func get()
{
if let url = NSURL(string: "https://www.hackingwithswift.com") {
    do {

        let JSONData = NSData(contentsOfURL: url)
        do {
            let JSON = try NSJSONSerialization.JSONObjectWithData(JSONData!, options:NSJSONReadingOptions(rawValue: 0))
            guard let JSONDictionary :NSDictionary = JSON as? NSDictionary else {
                print("Not a Dictionary")
                // put in function
                return
            }
            print("JSONDictionary! \(JSONDictionary)")
        }
        catch let JSONError as NSError {
            print("\(JSONError)")
        }
    } catch {
        // contents could not be loaded
    }
}
else
   {
    // the URL was bad!
  }
}

关于ios - 错误 - 线程 1 exc_bad_instruction(代码=exc_1386_invop 子代码=0x0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38889627/

相关文章:

ios - 选择或突出显示 UITableViewCell 时调用哪个方法

swift - 我在 xcode 中遇到错误(没有可用的重载)

ios - 使用纸质入职时出错

ios - 缩放 UIButton 动画 - Swift

ios - 如何刷新表格 View 但禁用弹跳?

swift - 执行相同的代码行

swift - 切换到 macOS Catalina 后,Modulemap 将无法编译 - tcp_var.h

swift - 测试变量是否在 Swift 的类中声明

objective-c - #define 常量中的字符串数组 - objective-c

ios - 重写 Swift 中行插入的 withRowAnimation 样式