IMDB 中的 lldb 错误 API

lldb Error in IMDB API

我想在我的 Xcode 输出中打印 IMDB JSON 请求。 无论用户向搜索栏写入什么内容,我都希望从 IMDB 获得 JSON 对 低俗小说 的请求,然后在 Xcode 输出中打印。

我的要求:http://www.omdbapi.com/?t=pulp+fiction 但它给出了 lldb 错误

Xcode 输出:

2017-05-05 20:13:12.363263+0300 IMDB Api Project[4327:696994] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/gurkan/Library/Developer/CoreSimulator/Devices/7DCF1A18-D92C-45BB-9F89-01EBF200DA41/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2017-05-05 20:13:12.388362+0300 IMDB Api Project[4327:696994] [MC] Reading from private effective user settings.

在搜索栏点击回车后。 (我写了一些东西然后点击了,我写的东西并不重要,因为我只想得到 低俗小说 现在用户写到搜索栏的任何内容。)

(lldb)

然后就出现了这个画面。

0_swift_bridgeNonVerbatimFromObjectiveC:

libswiftCore.dylib`_swift_bridgeNonVerbatimFromObjectiveC:
    0x109ebabd0 <+0>:   pushq  %rbp
    0x109ebabd1 <+1>:   movq   %rsp, %rbp
    0x109ebabd4 <+4>:   pushq  %r15
    0x109ebabd6 <+6>:   pushq  %r14
    0x109ebabd8 <+8>:   pushq  %r12
    0x109ebabda <+10>:  pushq  %rbx
    0x109ebabdb <+11>:  movq   %rdx, %r14
    0x109ebabde <+14>:  movq   %rsi, %r12
    0x109ebabe1 <+17>:  movq   %rdi, %r15
    0x109ebabe4 <+20>:  callq  0x109ebaed0               ; tryBridgeNonVerbatimFromObjectiveCUniversal(swift::HeapObject*, swift::TargetMetadata<swift::InProcess> const*, swift::OpaqueValue*)
    0x109ebabe9 <+25>:  testb  %al, %al
    0x109ebabeb <+27>:  je     0x109ebabf6               ; <+38>
    0x109ebabed <+29>:  popq   %rbx
    0x109ebabee <+30>:  popq   %r12
    0x109ebabf0 <+32>:  popq   %r14
    0x109ebabf2 <+34>:  popq   %r15
    0x109ebabf4 <+36>:  popq   %rbp
    0x109ebabf5 <+37>:  retq   
    0x109ebabf6 <+38>:  leaq   0x872bb(%rip), %rsi       ; protocol descriptor for Swift._ObjectiveCBridgeable
    0x109ebabfd <+45>:  movq   %r12, %rdi
    0x109ebac00 <+48>:  callq  0x109ee6de0               ; swift_conformsToProtocol
    0x109ebac05 <+53>:  movq   %rax, %rbx
    0x109ebac08 <+56>:  testq  %rbx, %rbx
    0x109ebac0b <+59>:  je     0x109ebac47               ; <+119>
    0x109ebac0d <+61>:  movq   %r12, %rdi
    0x109ebac10 <+64>:  movq   %rbx, %rsi
    0x109ebac13 <+67>:  callq  *(%rbx)
    0x109ebac15 <+69>:  movq   %r15, %rdi
    0x109ebac18 <+72>:  movq   %rax, %rsi
    0x109ebac1b <+75>:  callq  0x109eb54f0               ; swift_dynamicCastUnknownClass
    0x109ebac20 <+80>:  testq  %rax, %rax
    0x109ebac23 <+83>:  je     0x109ebacb2               ; <+226>
    0x109ebac29 <+89>:  movq   0x10(%rbx), %r9
    0x109ebac2d <+93>:  movq   %rax, %rdi
    0x109ebac30 <+96>:  movq   %r14, %rsi
    0x109ebac33 <+99>:  movq   %r12, %rdx
    0x109ebac36 <+102>: movq   %r12, %rcx
    0x109ebac39 <+105>: movq   %rbx, %r8
    0x109ebac3c <+108>: popq   %rbx
    0x109ebac3d <+109>: popq   %r12
    0x109ebac3f <+111>: popq   %r14
    0x109ebac41 <+113>: popq   %r15
    0x109ebac43 <+115>: popq   %rbp
    0x109ebac44 <+116>: jmpq   *%r9
    0x109ebac47 <+119>: movq   (%r12), %rax
    0x109ebac4b <+123>: xorl   %ecx, %ecx
    0x109ebac4d <+125>: cmpq   [=11=]x7ff, %rax              ; imm = 0x7FF 
    0x109ebac53 <+131>: cmoval %ecx, %eax
    0x109ebac56 <+134>: cmpl   [=11=]xf, %eax
    0x109ebac59 <+137>: je     0x109ebac96               ; <+198>
    0x109ebac5b <+139>: cmpl   [=11=]xd, %eax
    0x109ebac5e <+142>: jne    0x109ebacb2               ; <+226>
    0x109ebac60 <+144>: movq   0x8(%r12), %rax
    0x109ebac65 <+149>: movq   (%rax), %rax
    0x109ebac68 <+152>: xorl   %ecx, %ecx
    0x109ebac6a <+154>: cmpq   [=11=]x7ff, %rax              ; imm = 0x7FF 
    0x109ebac70 <+160>: cmoval %ecx, %eax
    0x109ebac73 <+163>: cmpl   [=11=]x80, %eax
    0x109ebac78 <+168>: ja     0x109ebac91               ; <+193>
    0x109ebac7a <+170>: leaq   0x766c7(%rip), %rbx       ; protocol witness table for Swift._BridgeableMetatype : Swift._ObjectiveCBridgeable in Swift
    0x109ebac81 <+177>: leaq   0x3c(%rip), %rcx          ; <+244>
    0x109ebac88 <+184>: movslq (%rcx,%rax,4), %rax
    0x109ebac8c <+188>: addq   %rcx, %rax
    0x109ebac8f <+191>: jmpq   *%rax
    0x109ebac91 <+193>: callq  0x109eb6260               ; swift_unreachable(char const*)
    0x109ebac96 <+198>: movq   0x10(%r12), %rax
    0x109ebac9b <+203>: testl  [=11=]xffffff, %eax           ; imm = 0xFFFFFF 
    0x109ebaca0 <+208>: jne    0x109ebacb2               ; <+226>
    0x109ebaca2 <+210>: testl  %eax, %eax
    0x109ebaca4 <+212>: js     0x109ebacb2               ; <+226>
    0x109ebaca6 <+214>: leaq   0x7669b(%rip), %rbx       ; protocol witness table for Swift._BridgeableMetatype : Swift._ObjectiveCBridgeable in Swift
    0x109ebacad <+221>: jmp    0x109ebac0d               ; <+61>
    0x109ebacb2 <+226>: leaq   0x4c3c8(%rip), %rax       ; "value type is not bridged to Objective-C"
    0x109ebacb9 <+233>: movq   %rax, 0xb9268(%rip)       ; gCRAnnotations + 8
    0x109ebacc0 <+240>: int3   
->  0x109ebacc1 <+241>: nopl   (%rax)

Main.storyboard: https://i.hizliresim.com/M03v57.png

Viewcontroller.swift:

//
//  ViewController.swift
//  IMDB Api Project
//
//  Created by gurkan on 5.05.2017.
//  Copyright © 2017 gurkan. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UISearchBarDelegate {


    @IBOutlet weak var searchBar: UISearchBar!

    @IBOutlet weak var imageView: UIImageView!

    @IBOutlet weak var titleLabel: UILabel!


    @IBOutlet weak var directorLabel: UILabel!

    @IBOutlet weak var ratingLabel: UILabel!

    @IBOutlet weak var actorsLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        searchBar.delegate = self
    }

    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {

        searchForMovie(title: searchBar.text!)
        searchBar.text = ""


    }

    func searchForMovie(title: String){

        //http://www.omdbapi.com/?t=pulp+fiction
        if let movie = title.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed){

            let url = URL(string: "http://www.omdbapi.com/?t=pulp+fiction")
            let session = URLSession.shared
            let task = session.dataTask(with: url!, completionHandler: { (data, response, error) in
                if error != nil {
                    print(error!)
                } else {

                    if data != nil {

                        do {

                            let jsonResult = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<String,String>


                            DispatchQueue.main.async {
                                print(jsonResult)
                            }

                        } catch {

                        }

                    }

                }

            })

            task.resume()

        }

    }
}

因此,我该如何解决这个 lldb 错误?我应该怎么做才能打印低俗小说的 IMDB JSON 请求?

Xcode版本:8.3.2版本 模拟器:iPhone 6(部署目标 10.3)

https://i.hizliresim.com/r3o2R7.png

每次你 "force" 使用 Swift 中的东西 ! 你 运行 有崩溃的风险。而且,当您同时发生许多事情时,要找出哪里出了问题会变得很棘手。

这样试试:

func searchForMovie(title: String) {

    //http://www.omdbapi.com/?t=pulp+fiction
    if let movie = title.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) {

        if let url = URL(string: "https://www.omdbapi.com/?t=pulp+fiction") {

            let session = URLSession.shared

            let task = session.dataTask(with: url, completionHandler: { (data, response, error) in

                if error != nil {
                    print(error!)
                } else {

                    if let d = data {

                        do {

                            let jsonResult = try JSONSerialization.jsonObject(with: d, options: JSONSerialization.ReadingOptions.mutableContainers)

                            print(jsonResult)

                        } catch {

                        }

                    }

                }

            })

            task.resume()

        }

    }

}