TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: why not async var?

Forums > 100 Days of Swift

Hello,

I am unable to understand the arguments put forward on why not async var here.

That attempts to create a variable asynchronously, then writes to it directly. Have we cancelled the async work? If not, when the async work completes will it overwrite our new value? Do we still need to use await when reading the value even after we’ve explicitly set it?

Can someone please explain (w.r.t. the quote) why not async var?

2      

let makes the variable a constant. Once set you can't change its value anymore. A async function could take a while to finish. In the example shown and if we could change the value of the async var it would not be clear which value username would contain. The result of the function (Taylor Swift) or Justin Bieber.

The let prevents this.

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.