Swift development skill
This skill guides AI agents and contributors working in the swift/ directory. It outlines target
boundaries, coding standards, testing patterns, and mandatory verification steps.
1. Specification and blueprint grounding
Before modifying or implementing Swift code, inspect the authoritative specifications:
- Protocol envelopes and schemas:
specification/v0_9_1/json/ defines wire-format types
and validation schemas.
- Component catalog schema:
basic/catalog.json defines
components, properties, and function signatures.
- Core module blueprint:
a2ui_core.blueprint.md specifies state
handling, JSON pointer rules, auto-vivification, and error semantics.
- Framework adapter blueprint:
a2ui_framework_adapter.blueprint.md specifies view mapping,
reactive subscription lifecycles, and layout behavior.
- Reference implementation:
renderers/web_core/ serves as
the canonical behavioral reference for edge-case resolution.
2. Swift target architecture
The Swift implementation uses targets defined in root Package.swift:
A2UIJSON (core/Sources/A2UIJSON): Pure
JSON Schema 2020-12 definitions and remote schema registry storage.
A2UICore (core/Sources/A2UICore): Stateful
runtime engine managing MessageProcessor, DataModel, SurfaceGroupModel, pointer evaluation,
and action routing.
BasicCatalog (core/Sources/BasicCatalog):
Core schema definitions and function handlers for Basic Catalog components.
A2UISwiftUI (swiftui/Sources/A2UISwiftUI):
SwiftUI adapter providing the root Surface view, recursive ComponentNodeView, and
environment keys.
BasicCatalogSwiftUI
(swiftui/Sources/BasicCatalog): Concrete
SwiftUI view implementations conforming to ComponentImplementation.
A2UISampleClient (swift/sample): Interactive iOS Gallery
application managed via Xcode project file.
3. Mandatory coding standards
All Swift code must strictly follow
swift/CODING_STANDARDS.md and the Google Swift Style Guide:
- One primary type per file: Every class, struct, enum, and protocol must live in a dedicated
file named after the type.
- 100-character line limit: No line of code, comment, docstring, or markdown may exceed 100
characters.
- 2-space indentation: Enforced by
swift-format.
- Apache 2.0 copyright header: Required on every new
.swift file:// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
- Safe optional handling: Never use force-unwrapping (
!) or forced tries (try!). Use
optional bindings (if let, guard let) or propagate throwing errors.
4. Swift Testing conventions
Tests use the native Swift Testing framework:
- Import
Testing instead of XCTest.
- Annotate test functions with
@Test.
- Use
#expect(...) for assertions.
- In tests, replace force unwraps with
try #require(...) to produce clean test failures instead of
crashes.
- Avoid
@testable import. Test only the public API surface.
- Use standard camelCase identifiers for test function names without backticks or spaces.
5. Verification workflow
After making any code changes in swift/, run this verification sequence from the repository root:
- Auto-format code:
swift-format format -i -r Package.swift swift/
- Lint check:
swift-format lint -r Package.swift swift/
- Run unit tests:
swift test
Or run filtered tests during iterative development:swift test --filter A2UICoreTests
swift test --filter A2UISwiftUITests
- Compile check:
swift build
6. Integration with repository skills
1---2name: a2ui-swift-development3description: Grounding, coding standards, testing practices, and verification workflows for developing in the A2UI Swift codebase (under the swift/ directory). Use whenever implementing features, modifying state logic, creating SwiftUI views, or writing tests in Swift.4---56# Swift development skill78This skill guides AI agents and contributors working in the `swift/` directory. It outlines target9boundaries, coding standards, testing patterns, and mandatory verification steps.1011---1213## 1. Specification and blueprint grounding1415Before modifying or implementing Swift code, inspect the authoritative specifications:1617- **Protocol envelopes and schemas**:18 [`specification/v0_9_1/json/`](../../../specification/v0_9_1/json/) defines wire-format types19 and validation schemas.20- **Component catalog schema**:21 [`basic/catalog.json`](../../../specification/v0_9_1/catalogs/basic/catalog.json) defines22 components, properties, and function signatures.23- **Core module blueprint**:24 [`a2ui_core.blueprint.md`](../../../blueprints/modules/a2ui_core.blueprint.md) specifies state25 handling, JSON pointer rules, auto-vivification, and error semantics.26- **Framework adapter blueprint**:27 [`a2ui_framework_adapter.blueprint.md`][framework-adapter-blueprint] specifies view mapping,28 reactive subscription lifecycles, and layout behavior.29- **Reference implementation**: [`renderers/web_core/`](../../../renderers/web_core/) serves as30 the canonical behavioral reference for edge-case resolution.3132[framework-adapter-blueprint]: ../../../blueprints/modules/a2ui_framework_adapter.blueprint.md3334---3536## 2. Swift target architecture3738The Swift implementation uses targets defined in root [`Package.swift`](../../../Package.swift):3940- **`A2UIJSON`** ([`core/Sources/A2UIJSON`](../../../swift/core/Sources/A2UIJSON)): Pure41 JSON Schema 2020-12 definitions and remote schema registry storage.42- **`A2UICore`** ([`core/Sources/A2UICore`](../../../swift/core/Sources/A2UICore)): Stateful43 runtime engine managing `MessageProcessor`, `DataModel`, `SurfaceGroupModel`, pointer evaluation,44 and action routing.45- **`BasicCatalog`** ([`core/Sources/BasicCatalog`](../../../swift/core/Sources/BasicCatalog)):46 Core schema definitions and function handlers for Basic Catalog components.47- **`A2UISwiftUI`** ([`swiftui/Sources/A2UISwiftUI`](../../../swift/swiftui/Sources/A2UISwiftUI)):48 SwiftUI adapter providing the root `Surface` view, recursive `ComponentNodeView`, and49 environment keys.50- **`BasicCatalogSwiftUI`**51 ([`swiftui/Sources/BasicCatalog`](../../../swift/swiftui/Sources/BasicCatalog)): Concrete52 SwiftUI view implementations conforming to `ComponentImplementation`.53- **`A2UISampleClient`** ([`swift/sample`](../../../swift/sample)): Interactive iOS Gallery54 application managed via Xcode project file.5556---5758## 3. Mandatory coding standards5960All Swift code must strictly follow61[`swift/CODING_STANDARDS.md`](../../../swift/CODING_STANDARDS.md) and the Google Swift Style Guide:62631. **One primary type per file**: Every class, struct, enum, and protocol must live in a dedicated64 file named after the type.652. **100-character line limit**: No line of code, comment, docstring, or markdown may exceed 10066 characters.673. **2-space indentation**: Enforced by `swift-format`.684. **Apache 2.0 copyright header**: Required on every new `.swift` file:69 ```swift70 // Copyright 2024 Google LLC71 //72 // Licensed under the Apache License, Version 2.0 (the "License");73 // you may not use this file except in compliance with the License.74 // You may obtain a copy of the License at75 //76 // https://www.apache.org/licenses/LICENSE-2.077 //78 // Unless required by applicable law or agreed to in writing, software79 // distributed under the License is distributed on an "AS IS" BASIS,80 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.81 // See the License for the specific language governing permissions and82 // limitations under the License.83 ```845. **Safe optional handling**: Never use force-unwrapping (`!`) or forced tries (`try!`). Use85 optional bindings (`if let`, `guard let`) or propagate throwing errors.8687---8889## 4. Swift Testing conventions9091Tests use the native Swift Testing framework:9293- Import `Testing` instead of `XCTest`.94- Annotate test functions with `@Test`.95- Use `#expect(...)` for assertions.96- In tests, replace force unwraps with `try #require(...)` to produce clean test failures instead of97 crashes.98- Avoid `@testable import`. Test only the public API surface.99- Use standard camelCase identifiers for test function names without backticks or spaces.100101---102103## 5. Verification workflow104105After making any code changes in `swift/`, run this verification sequence from the repository root:1061071. **Auto-format code**:108 ```bash109 swift-format format -i -r Package.swift swift/110 ```1112. **Lint check**:112 ```bash113 swift-format lint -r Package.swift swift/114 ```1153. **Run unit tests**:116 ```bash117 swift test118 ```119 Or run filtered tests during iterative development:120 ```bash121 swift test --filter A2UICoreTests122 swift test --filter A2UISwiftUITests123 ```1244. **Compile check**:125 ```bash126 swift build127 ```128129---130131## 6. Integration with repository skills132133- **Blueprint compliance**: When updating models or schemas, check compliance with134 [`a2ui-blueprint-compliance`](../../../blueprints/skills/a2ui-blueprint-compliance/SKILL.md).135- **Test quality**: Verify assertion strength and boundary cases with136 [`a2ui-test-quality-check`](../a2ui-test-quality-check/SKILL.md).137- **Documentation sync**: Ensure documentation reflects code changes using138 [`a2ui-doc-sync-check`](../a2ui-doc-sync-check/SKILL.md).