Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why @escaping #1

Open
Ricardo1980 opened this issue Mar 15, 2018 · 2 comments
Open

Why @escaping #1

Ricardo1980 opened this issue Mar 15, 2018 · 2 comments

Comments

@Ricardo1980
Copy link

Hi!

I wonder why these closures are escaping
https://github.com/koromiko/Tutorial/blob/master/MVVMPlayground/MVVMPlayground/Service/APIService.swift

Thanks.

@ColourfulSquirrel
Copy link

“Escaping Closures
A closure is said to escape a function when the closure is passed as an argument to the function, but is called after the function returns. When you declare a function that takes a closure as one of its parameters, you can write @escaping before the parameter’s type to indicate that the closure is allowed to escape.”

Excerpt From: Apple Inc. “The Swift Programming Language (Swift 4).” iBooks. ”

@koromiko
Copy link
Owner

hi, thank you @tbfyniiswcy for explaining 👍
Yes, I created this class only for simulating network requests, which is usually executed on the background thread (and it is in the example). Thus, we must use @escaping. Otherwise, the code won't even compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants