I want to print IMDB JSON request in my Xcode Output. Whatever user writes to search bar I want to get JSON request for pulp fiction from IMDB then print in Xcode Output.
My request: http://www.omdbapi.com/?t=pulp+fiction But it gives, lldb error
Xcode Output:
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.
After clicking enter in the search bar. (I writed something then clicked, what I writed is not important because I just want to get for pulp fiction whatever user write to searchbar for now .)
(lldb)
Then this screen came into.
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 $0x7ff, %rax ; imm = 0x7FF
0x109ebac53 <+131>: cmoval %ecx, %eax
0x109ebac56 <+134>: cmpl $0xf, %eax
0x109ebac59 <+137>: je 0x109ebac96 ; <+198>
0x109ebac5b <+139>: cmpl $0xd, %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 $0x7ff, %rax ; imm = 0x7FF
0x109ebac70 <+160>: cmoval %ecx, %eax
0x109ebac73 <+163>: cmpl $0x80, %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 $0xffffff, %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()
}
}
}
As a result, How can I solve this lldb error? What should I do to print IMDB JSON request for pulp fiction?
Xcode version: Version 8.3.2 Simulator: iPhone 6 (Deployment target 10.3)
Every time you "force" something in Swift using !
you run the risk of a crash. And, when you've got numerous things going on at the same time, it can get tricky to figure out where it went wrong.
Try it like this:
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()
}
}
}