swiftchatejabberdxmppframework

Ambiguous use of 'dispatch_get_main_queue()' - XMPP


I am doing a project with chat activity using XMPP.I am using the following code to generate it,

 var stream:XMPPStream!

 let xmppRosterStorage = XMPPRosterCoreDataStorage()
 var xmppRoster: XMPPRoster!

  override func viewDidLoad() {
    super.viewDidLoad()

    xmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage)

    stream = XMPPStream()
    stream.addDelegate(self, delegateQueue: dispatch_get_main_queue())

    xmppRoster.activate(stream)

    let button = UIButton()
    button.backgroundColor = UIColor.red
    button.setTitle("SendMessage", for: .normal)
    button.frame = CGRect(x: 90, y: 100, width: 300, height: 40)//CGRect(90, 100, 300, 40)
    button.addTarget(self, action: #selector(self.sendMessage), for: .touchUpInside)

    self.view.addSubview(button)
    stream.myJID = XMPPJID(string: "test@localhost")

    do {
       try stream.connect(withTimeout: 30)
    }
    catch {
       print("error occured in connecting")
    }

    }

I refer this tutorial. but I am getting some issue in the following line

stream.addDelegate(self, delegateQueue: dispatch_get_main_queue())

the issue is,

Ambiguous use of 'dispatch_get_main_queue()'

The main thing is I am using Swift4.2

Anyone please help me to find out the solution. Thanks...


Solution

  • The new syntax is DispatchQueue.main, or just .main if the context requires a DispatchQueue. Thus:

    stream.addDelegate(self, delegateQueue: .main)