Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Swift Basics

Swift HOME Swift Intro Swift Get Started Swift Syntax Swift Statements Swift Output Swift Comments Swift Variables Swift Data Types Swift Type Casting Swift Operators Swift Strings Swift Arrays Swift Ranges Swift If...Else Swift Switch Swift While Loop Swift For Loop Swift Break/Continue Swift Collections

Swift Types & Functions

Swift Functions Swift Optionals Swift Enums & Patterns Swift Closures Tuples & Type Aliases

Swift Object Model

Swift OOP Swift Inheritance Swift Polymorphism Swift Protocols Swift Generics Swift Extensions Access Control Initializers Deinitializers Value Semantics & COW Equatable & Comparable

Swift Robustness & Async

Swift Error Handling Swift Concurrency Swift Memory

Swift Tooling

Swift Package Manager

SwiftUI Basics

SwiftUI Intro iOS Project Setup SwiftUI Layout SwiftUI Navigation SwiftUI Data Flow SwiftUI Lists & Forms SwiftUI Animations SwiftUI Gestures SwiftUI Modifiers & ViewBuilder SwiftUI Previews SwiftUI Accessibility SwiftUI Styling & Theming

SwiftUI Data & Architecture

Networking Persistence Persistence (Core Data) MVVM Architecture AppStorage & SceneStorage Testing SwiftUI

iOS Capabilities

Privacy & Permissions Push Notifications Widgets & Extensions Background Work Core Location App Clips Keychain Basics CloudKit File System Background URLSession MapKit

iOS Quality & Compliance

Localization Accessibility App Privacy In-App Purchases Analytics & Reporting Testing with XCTest

iOS Release & Distribution

Assets & App Icons Signing & Distribution TestFlight & App Store Ship Your First App

Swift Exercises

Swift Exercises Swift Quiz

iOS Project Setup


iOS Project Setup

Create a new SwiftUI app in Xcode, configure signing and capabilities, and set your deployment targets.


Create a New Project in Xcode

Use the App template, choose Swift and SwiftUI, set your organization identifier (e.g.

com.example), and pick a bundle identifier like com.example.MyApp.

Checklist

  • Product Name, Team, Organization Identifier
  • Interface: SwiftUI; Language: Swift; Use Core Data (optional)
  • Minimum iOS version (e.g. iOS 15+)

Use this checklist to ensure your project is created with the right templates, identifiers, and minimum OS version.


Run Examples in Xcode

Standard workflow (used in this tutorial)

Each example is organized into three files so you can run it as a small app:

  1. Demo.swift: The example's main code (view and/or supporting types).
  2. ContentView.swift: Shows the demo (uses types from Demo.swift).
  3. App.swift: Stable entry point with WindowGroup { ContentView() }.

Tip: In your own Xcode project, avoid duplicate ContentView declarations.

Reuse a single ContentView and update its body per example, or create a simple chooser that navigates to uniquely named demo views.

Optional: Canvas Preview

You can also run any example via Xcode's Canvas Preview without changing your app entry point.

  1. Create a SwiftUI View: File → New → File... → SwiftUI View. Paste the example view code.
  2. Add a Preview: Use a PreviewProvider or the #Preview macro.

Example

import SwiftUI

struct Demo_Previews: PreviewProvider {
  static var previews: some View { Demo() }
}
import SwiftUI

#Preview { Demo() }
  1. Open Canvas: Editor → Canvas. Build once if the preview is unavailable.
  2. Run & Interact: Click Resume/Play; use the device selector to switch models.

Troubleshooting: If the preview fails to load, Build, then Clean Build Folder.

Ensure the target is iOS and the file imports SwiftUI.



Project Settings

In the project navigator, select the app target and configure:

  • Signing & Capabilities: Select your team and enable automatic signing.
  • Deployment Info: Minimum iOS version, supported orientations.
  • Bundle Identifier: Matches the one you will register in App Store Connect.

Tip: Use Assets.xcassets for your app icon and images.

Add capabilities (e.g., Push Notifications) here when needed.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.