A
A
Alexander2018-02-22 17:08:23
Swift
Alexander, 2018-02-22 17:08:23

How to pass values ​​from a callback function in swift 3?

Hi all.
There is a variable var menus: Any = []in which you need to write data from here

self.httpRequest.getJsonMenu(){ code in
        print("Menu2: \(code)")
        return code
}

Thanks in advance

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2018-02-28
@vetlugins

Declared a variable var menus: Any = []globally
PS Most likely my fault, I did not explain the question correctly .. This function performed an asynchronous request

B
briahas, 2018-03-09
@briahas

Solving the problem by translating a variable into a global scope is a bad option, in terms of application architecture. If architecture is not important to you - then ¯\_(ツ)_/¯

A
arturios571, 2018-03-24
@arturios571

So what's the question?
You have an array in a closure doing array.append(result)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question