emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.57k stars 411 forks source link

delegate = self throwing type error #538

Open hothsolo opened 11 months ago

hothsolo commented 11 months ago

When I do the mqtt5.delegate = self, I get an error saying it cannot assign a value of type ViewController to this variable. THanks for any help.

Cj

leeway1208 commented 11 months ago

We can share the code here and then know about the issues.

hothsolo commented 11 months ago

I figured it out. I just didn't add the extensions. I think it would be very helpful if that step was on the main page here.

Cj

hothsolo commented 11 months ago

So having a couple issues still. First, I'm trying to integrate this into my own code. So I don't have your ChatViewController. But the viewcontrollerextension requires it in the mqtt func inside there. Can I just eliminate that code? Second, this animal variable. Can you explain what that is used for?

Cj

hothsolo commented 11 months ago

Or maybe I can just use this instead of the delegate? I'm not sure I understand exactly what the delegate is doing.

Capture

hothsolo commented 11 months ago

Is there a closure for didConnectAck? If so, please, how do you use it?

Cj

leeway1208 commented 11 months ago

Is there a closure for didConnectAck? If so, please, how do you use it?

Cj

Hello. There is the demo.

   mqtt5 = CocoaMQTT5(clientID: clientID, host: defaultHost, port: 1883)
   mqtt5!.didReceiveMessage = { mqtt, message, msgid
               ,publishRecProperties  in print("Message received in topic \(message.topic) with payload \(message.string!)")
   }