Xcode's coding agents let you generate multiple SwiftUI UI variations from a single descriptive prompt, enabling rapid design exploration directly in native code. Combined with Xcode Previews, you can iterate on layouts, animations, and real content states without leaving the IDE.
โข Agents produce real, compilable SwiftUI code โ not throwaway mockups โ so prototypes can evolve directly into production screens
โข Asking for multiple named previews in one prompt lets you compare divergent design directions side-by-side instantly
โข Bringing in realistic sample data via agents exposes edge cases (empty states, long text, dynamic color) before real users encounter them
Demonstrates how to structure SwiftUI previews so a single file shows multiple named design variations side-by-side โ the pattern coding agents in Xcode produce when asked for divergent UI directions.
import SwiftUI
// MARK: - Sample Data (keep in its own file for reuse across prototypes)
struct BookClubSampleData {
static let currentBook = Book(
title: "The Name of the Wind",
author: "Patrick Rothfuss",
coverColor: Color(red: 0.55, green: 0.27, blue: 0.07)
)
static let members: [Member] = [
Member(name: "Alice", booksRead: 12),
Member(name: "Bruno", booksRead: 9),
Member(name: "Cleo", booksRead: 7),
Member(name: "Dana", booksRead: 5)
]
static let nextMeeting: String? = "Thursday 7 PM ยท The Reading Loft"
}
struct Book: Identifiable {
let id = UUID()
var title: String
var author: String
var coverColor: Color
}
struct Member: Identifiable {
let id = UUID()
var name: String
var booksRead: Int
}
// MARK: - Variation A: "Cozy" โ warm tones, prominent book cover
struct CozyClubView: View {
let book = BookClubSampleData.currentBook
let members = BookClubSampleData.members
let nextMeeting = BookClubSampleData.nextMeeting
var body: some View {
NavigationStack {
ScrollView {
VStack(alignment: .leading, spacing: 20) {
// Current book hero
HStack(spacing: 16) {
RoundedRectangle(cornerRadius: 8)
.fill(book.coverColor)
.frame(width: 72, height: 108)
.shadow(radius: 4)
VStack(alignment: .leading, spacing: 4) {
Text("Now Reading")
.font(.caption)
.foregroundStyle(.secondary)
Text(book.title)
.font(.headline)
.fontDesign(.serif)
Text(book.author)
.font(.subheadline)
.foregroundStyle(.secondary)
}
}
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.background(.brown.opacity(0.1), in: RoundedRectangle(cornerRadius: 14))
// Next meeting
if let meeting = nextMeeting {
Label(meeting, systemImage: "calendar")
.font(.subheadline)
.padding(.horizontal)
} else {
Button("Schedule Next Meeting") {}
.padding(.horizontal)
}
// Leaderboard (collapsed if > 3 members)
LeaderboardSection(members: members)
}
.padding()
}
.navigationTitle("Cozy Club")
.navigationBarTitleDisplayMode(.large)
}
}
}
// MARK: - Variation B: "Editorial" โ clean typography, minimal chrome
struct EditorialClubView: View {
let book = BookClubSampleData.currentBook
let members = BookClubSampleData.members
var body: some View {
NavigationStack {
List {
Section {
VStack(alignment: .leading, spacing: 6) {
Text(book.title)
.font(.system(.title2, design: .serif, weight: .bold))
Text(book.author)
.font(.subheadline)
.foregroundStyle(.secondary)
}
.padding(.vertical, 8)
} header: {
Text("Current Read")
}
Section("Standings") {
ForEach(Array(members.enumerated()), id: \.element.id) { index, member in
HStack {
Text("\(index + 1)")
.font(.caption.monospacedDigit())
.foregroundStyle(.secondary)
.frame(width: 24)
Text(member.name)
Spacer()
Text("\(member.booksRead) books")
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
}
.navigationTitle("Editorial")
}
}
}
// MARK: - Shared sub-component
struct LeaderboardSection: View {
let members: [Member]
@State private var expanded = false
private let collapsedLimit = 3
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text("Standings")
.font(.headline)
let visible = expanded ? members : Array(members.prefix(collapsedLimit))
ForEach(Array(visible.enumerated()), id: \.element.id) { index, member in
HStack {
Text("#\(index + 1)").foregroundStyle(.secondary).frame(width: 32)
Text(member.name)
Spacer()
Text("\(member.booksRead)").bold()
}
.padding(.vertical, 2)
}
if members.count > collapsedLimit {
Button(expanded ? "Show Less" : "Show All \(members.count)") {
withAnimation(.spring(duration: 0.35)) { expanded.toggle() }
}
.font(.caption)
}
}
.padding(.horizontal)
}
}
// MARK: - Named Previews (mirrors what Xcode coding agents generate per prompt)
#Preview("Cozy") {
CozyClubView()
}
#Preview("Editorial") {
EditorialClubView()
}
#Preview("Empty State โ No Meeting") {
CozyClubView()
}Liquid Glass is Apple's new material and visual design language introduced in iOS 27, bringing translucent, refractive glass-like surfaces to system and custom UI elements. It replaces the frosted vibrancy aesthetic with a more dynamic, depth-aware material that responds to content beneath it.
PaperKit is Apple's full-featured canvas framework โ previously internal-only โ now publicly available in iOS/macOS/visionOS 27. It powers the drawing and markup experience in Notes, Preview, and Freeform, giving developers access to a complete pencil, shapes, images, and text canvas with a rich data model.
Xcode 27 introduces a fully customizable toolbar and theme system, untitled scratch projects, coding agent integration directly in the editor, and the new Device Hub for evaluating apps across simulators and physical devices side-by-side.
In-depth guide
SwiftUI & Liquid Glass in iOS 27 โAgents produce plausible but not always optimal layouts โ always review and refactor generated code. Vague prompts produce generic UIs; specificity is critical. Sample data files should be kept separate so they can be reused across prototype iterations. Don't treat agent output as final design decisions โ use your own judgment to evaluate and remix results.
Coding agents in Xcode require an internet connection and an Apple Developer account; on-device agent execution may require Apple Silicon Mac for Xcode
iOS 27 introduces new SwiftUI drag and drop APIs including reorderable, reorderContainer, dragContainer, and configuration modifiers that enable reordering within and across collections, multi-item drag, and fine-grained control over how data is transferred during drag and drop operations.