bhylu.com

Advertisements

Swift Previews and Variants

Use previews to inspect explicit UI states rather than treating one picture as a test suite. Requires Mac/Xcode; this Apple-only source was not SDK-compiled or run here.

How it works

Xcode previews need a compatible Apple SDK and macro tooling. Provide different text sizes, colour schemes and data states, including empty and error cases. A preview can reveal layout issues, but it does not replace a simulator build, interaction test, VoiceOver pass or device capability check.

Apple-only setup and review status

Create a separate iOS SwiftUI App learning project in a suitable Xcode version, choose an appropriate simulator/device and replace the generated app/view Swift source with this complete file. Keep one @main entry point. Widget and App Clip lessons explicitly require their own extension/clip targets instead; capability, purpose-string, entitlement and account steps in the lesson must be completed separately. No Xcode project, signing certificate, account or service was provisioned here.

Bhylu has no Swift browser runner. The JavaScript/Python editors do not run these sources; Apache, PHP and MySQL are not required. Downloads are source text, never executable teaching endpoints.

Download the complete previews.swift · Download all source files with hash checks

For the optional collection, save download-examples.mjs in a new folder and run node download-examples.mjs. A local preview uses node download-examples.mjs http://127.0.0.1:8000/examples/swift/. It refuses an existing bhylu-swift-examples folder and installs or executes no Swift automatically. Apple-only files remain separate Xcode learning examples, not a portable Swift package target.

Example

previews.swift

// Apple-only learning file: iOS 17+ target with a suitable Xcode SDK.
// Not compiled or run in this Windows/Linux review.
import SwiftUI

#Preview("Ready") { DemoView().preferredColorScheme(.light) }
#Preview("Long title, full, dark") {
    DemoView(title: "Cedar community pottery workshop collection desk", available: 0)
        .environment(\.dynamicTypeSize, .accessibility3).preferredColorScheme(.dark)
}

struct DemoView: View {
    var title = "Cedar workshop"
    var available = 6
    var body: some View {
        VStack(alignment: .leading, spacing: 16) {
            Text(title).font(.title)
            Text(available == 0 ? "No places ready" : "\(available) places ready")
        }.padding()
    }
}

@main
struct WorkshopDemoApp: App {
    var body: some Scene { WindowGroup { DemoView() } }
}

Expected behaviour and manual checks

Manual Xcode check: open both previews, increase text size and run the app separately. Confirm long text wraps and the full state remains legible. Preview macros and rendering were not executed here.

Each preview supplies its own state rather than depending on a running service. The regular app entry point stays separate. A custom environment model must also be injected in a preview that reads it.

Primary references: The Swift Programming Language and Apple framework documentation. Use the selected platform’s current requirements. Fictional workshop examples do not establish production safety or deployment approval.

Advertisements