Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

How to pass around client object throughout app? #82

Closed
sirvon opened this issue Feb 27, 2017 · 1 comment
Closed

How to pass around client object throughout app? #82

sirvon opened this issue Feb 27, 2017 · 1 comment
Labels

Comments

@sirvon
Copy link

sirvon commented Feb 27, 2017

bot.onClientInitalization = { (client: Client) in
            DispatchQueue.main.async(execute: {
                client.messageEventsDelegate = self
                client.connectionEventsDelegate = self
                //send client to object cache? 
                //put client somewhere to use it again elsewhere or
               // try another design?
            })

or should i really be doing webAPI stuff here...

    func connected(_ client: Client) {
        print("\(client.connected) \("connected FromForeground")")
        //send client to object cache? 
        //put client somewhere to use it again elsewhere or
        // try another design?
    }

I see there's a few ways to get the initialized client object so that I can call WebAPI.
But how can I pass this object around the app and use it anywhere in the app?

Or is it cool to just do initialization again anywhere when I need the client object?

@pvzig pvzig added the question label Feb 28, 2017
@pvzig
Copy link
Owner

pvzig commented Feb 28, 2017

Hey Sirvon,

Without knowing exactly what you're trying to do it's hard to know what exactly the right approach would be but you have a few options:

  1. If you're responding to the initialization event, you can use the Client object that's passed via that closure.
  2. If you're responding to a specific event, almost all of the delegate methods send a Client instance that you can use.
  3. If you need to make requests independent of these situations, you can initalize your own instance of WebAPI

@pvzig pvzig closed this as completed Feb 28, 2017
@pvzig pvzig reopened this Feb 28, 2017
@pvzig pvzig closed this as completed Feb 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants