Await for calling async functions
📖 Scenario: You are building a simple Swift program that fetches user data asynchronously, simulating a network call.
🎯 Goal: Learn how to call an async function and use await to get its result properly.
📋 What You'll Learn
Create an async function called
fetchUserName() that returns a StringCreate a variable called
userName to store the result of calling fetchUserName()Use
await keyword to wait for the async function resultPrint the
userName variable💡 Why This Matters
🌍 Real World
Async functions are used to fetch data from the internet or perform tasks that take time without freezing the app.
💼 Career
Understanding async/await is essential for modern Swift development, especially for apps that communicate with servers or do background work.
Progress0 / 4 steps