0
0
iOS Swiftmobile~5 mins

First iOS app in iOS Swift

Choose your learning style9 modes available
Introduction

Making your first iOS app helps you learn how to create simple apps that run on iPhones. It shows you how to display text and respond to user actions.

You want to create a simple app that shows a greeting message.
You want to learn how to build apps that run on iPhones.
You want to understand the basics of app structure and user interface.
You want to test how to add buttons and text on the screen.
You want to start a project that can grow into a bigger app later.
Syntax
iOS Swift
import SwiftUI

@main
struct MyFirstApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}

struct ContentView: View {
  var body: some View {
    Text("Hello, world!")
      .padding()
  }
}

The @main attribute marks the app's entry point.

ContentView defines what the user sees on the screen.

Examples
This shows a blue title text on the screen.
iOS Swift
Text("Welcome to my app!")
  .font(.title)
  .foregroundColor(.blue)
This creates a button that prints a message when tapped.
iOS Swift
Button("Tap me") {
  print("Button tapped")
}
Sample App

This app shows a large greeting text and a blue button below it. When you tap the button, it prints a message in the console.

iOS Swift
import SwiftUI

@main
struct MyFirstApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}

struct ContentView: View {
  var body: some View {
    VStack {
      Text("Hello, world!")
        .font(.largeTitle)
        .padding()
      Button("Tap me") {
        print("Button was tapped")
      }
      .padding()
      .background(Color.blue)
      .foregroundColor(.white)
      .cornerRadius(8)
    }
  }
}
OutputSuccess
Important Notes

Use the Xcode simulator to see your app running on a virtual iPhone.

Remember to check the console to see print messages when you tap buttons.

Start simple and add more features as you learn.

Summary

Your first iOS app shows text and a button on the screen.

Use Text to display words and Button to handle taps.

The @main struct starts your app and shows the main view.