swiftcnearly preview

Installation

Add SwiftCN as a package, or copy the source into your project.

Requirements

Build with Xcode 26 or later (Swift 6.2). Apps deploy to iOS 17 or macOS 14 and later. The package checks for Liquid Glass at run time and uses native fallbacks on earlier systems.

Xcode

Open File → Add Package Dependencies. Enter this repository URL:

https://github.com/cbethin/swiftcn.git

Select the main branch and add the SwiftCN product to your app target. The project has no stable release tag yet.

Then open the app target's Build Phases, expand Run Build Tool Plug-ins, and add SwiftCNLintPlugin. Every build then checks your class strings before Swift compiles, and an invalid class fails the build on its line. Xcode asks you to trust the plugin the first time it runs.

Swift Package Manager

Add the package dependency, its product, and the build plugin to your target. The plugin checks class strings before the target compiles, so an invalid class fails the build. This complete manifest uses a library target named ProjectUI:

Package.swift
// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "ProjectUI",
    platforms: [.iOS(.v17), .macOS(.v14)],
    products: [.library(name: "ProjectUI", targets: ["ProjectUI"])],
    dependencies: [
        .package(url: "https://github.com/cbethin/swiftcn.git", branch: "main")
    ],
    targets: [
        .target(
            name: "ProjectUI",
            dependencies: [.product(name: "SwiftCN", package: "swiftcn")],
            plugins: [.plugin(name: "SwiftCNLintPlugin", package: "swiftcn")]
        )
    ]
)

Put your views in Sources/ProjectUI. For an existing package, keep its products and targets, then add the matching dependency entries. The Xcode workflow above adds SwiftCN directly to a SwiftUI app target.

The main branch can change between package resolutions. Commit your app's Package.resolved to share the selected revision. For a fixed dependency, replace branch: "main" with revision: "<full commit SHA>".

Copy the source

Clone the repository and copy every Swift file from Sources/SwiftCN into your app target. Keep its MIT license beside the copied source. Omit import SwiftCN when the files belong to your app module.

For example, run these commands from your app repository. Choose an unused clone destination:

git clone https://github.com/cbethin/swiftcn.git ../swiftcn-source
mkdir -p Vendor/SwiftCN
cp ../swiftcn-source/Sources/SwiftCN/*.swift Vendor/SwiftCN/
cp ../swiftcn-source/LICENSE Vendor/SwiftCN/LICENSE

Add Vendor/SwiftCN to your Xcode project and select your app target for all Swift files. Check class strings with the clone: swift run --package-path ../swiftcn-source swiftcn-lint . Review source changes when you update your copy. Keep your app's recipes in a separate file to simplify those updates.

The library has no runtime dependencies. The repository's snapshot dependency belongs to its test targets. Source ownership requires the complete runtime source, not the demo or tests.

Your first view

import SwiftUI
import SwiftCN

struct Welcome: View {
    var body: some View {
        Text("Hello, SwiftUI.")
            .tw("text-lg font-semibold p-4 bg-surface rounded-lg")
    }
}

Continue with the complete quick start, including native state, a button, and app-wide rules. See troubleshooting if the import fails.

On this page