Menu
Coddy logo textTech

SwiftUI Playground

Write, run, and share code snippets - no setup required.

ContentView.swift
Preview

Run SwiftUI online and see the app on an iPhone

A free online SwiftUI playground. Write a ContentView and your views appear on an iPhone-sized screen next to the code. Buttons, toggles and text fields respond to taps, so @State changes show up the way they do on a device. No Mac, no Xcode, no simulator to download.

Your code is compiled with swiftc against Coddy's own implementation of SwiftUI, the same one that powers the live preview in Coddy's SwiftUI lessons. It covers the everyday API: stacks, Text, Image(systemName:), Button, Toggle, TextField, Slider, Stepper, Picker, List, ForEach, Form, NavigationStack, sheets and alerts, with @State, @Binding, ObservableObject and @Published. It is not Apple's framework, so Apple-only frameworks such as UIKit, MapKit and Core Data are not available.

What makes this SwiftUI playground useful

  • A live iPhone preview: the screen renders at iPhone size in a device frame, with a status bar and the Dynamic Island, so a layout looks the way it would on a phone.
  • Tap the app. Buttons, toggles, steppers and text fields respond, and the preview replays your taps against fresh state, so @State and @Binding behave as they do in a real app.
  • Auto preview: the screen rebuilds a moment after you stop typing, and the refresh button starts the app over. Compiler errors point at the line in your file.
  • SwiftUI code suggestions in the editor: modifiers after a dot, the values an argument takes (.font(., .foregroundStyle(.), property wrappers after @ and SF Symbol names.
  • Save a screenshot of the phone as a PNG, and download your ContentView.swift to open in Xcode later. Files pasted from Xcode build too: #Preview blocks are ignored.

What you can build in the SwiftUI playground

  • A to-do list with List, ForEach($items) and a Toggle per row, plus a TextField and a button that adds new rows.
  • A settings screen: a Form with sections, a Picker, a Stepper and a Slider, all bound to @State.
  • Navigation: a NavigationStack with a title and NavigationLink rows that push a detail view.
  • Layout experiments: VStack, HStack and ZStack with .padding, .frame, .background and rounded shapes, to see how modifiers stack.

Online SwiftUI playground FAQ

Can I run SwiftUI without a Mac?
Yes. This playground runs in any modern browser, on Windows, Linux, a Chromebook or an iPad. Your code is compiled on Coddy's servers and the screen is drawn in the page, so you do not need Xcode, a Mac or the iOS simulator to try SwiftUI.
Is the online SwiftUI playground free?
Yes. It is free with no sign-up: open the page, edit the code and watch the phone.
Is this Apple's SwiftUI?
No. It is Coddy's own implementation of SwiftUI's views, modifiers and property wrappers, compiled with swiftc and drawn as an iPhone screen. Everyday SwiftUI code runs unchanged, and the preview is the same one Coddy's SwiftUI lessons use and grade with. Apple-only frameworks such as UIKit, MapKit and Core Data are not available, and animations show their end state.
Can I use @Observable or #Preview?
Use ObservableObject with @Published and @StateObject for shared data. The @Observable macro and #Preview need Xcode's macro plugins; #Preview blocks are ignored, so a file pasted from Xcode still builds, and the app shows ContentView. You can also add your own @main App struct.
How do I learn SwiftUI after trying the playground?
Change the sample app and tap through it in the preview. When you want a structured path, Coddy's SwiftUI course teaches views, modifiers, stacks, @State, lists, navigation, @Binding and observable data in short lessons, each with the same live iPhone preview.

Useful tools for SwiftUI

Free, browser-based tools that pair well with the SwiftUI Playground - all part of Coddy.