No description
- Swift 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| examples | ||
| examples-swift | ||
| pkg | ||
| tools | ||
| .gitignore | ||
| INDEX.txt | ||
| README.md | ||
Swift by Example
Go by Example translated to the simplest Swift
we could write: imperative, zero inheritance in the translation, neat
functional tricks only — plus a Swift-only tour (OO included) and a
package chapter that finishes what the stdlib can't. Every script chapter
is self-contained: swift examples/05-for.swift is go run for.go.
Layout
examples/ all 85 chapters, numbered per gobyexample's own order
examples-swift/ 19 Swift-only pages: language gaps (optionals, guard,
closures-to-HOFs, grapheme strings), the 6-page OO tour,
NIO server family, AoC + Testing capstones
pkg/ 11 SwiftPM packages (NIO servers, ArgumentParser CLIs,
embed resources, testing tour)
tools/serve-docs.swift
browsable reader: `swift tools/serve-docs.swift` →
http://127.0.0.1:8080 — all chapters, comments/code
side by side, prev/next 1…104 (zero dependencies)
run-all.sh harness: runs every file, diffs its `//>` expect block
INDEX.txt chapter order; line number = filename prefix
TRANSLATING.md style rules, known traps, package-chapter notes
SKIPPED.md package chapter + supplant + deviation ledger
Ground truth for future chapters: clone mmcgrana/gobyexample
into upstream/ (gitignored) — see TRANSLATING.md.
Highlights beyond the translation
- OO tour (
examples-swift/classes-and-inheritance.swift…composition-and-delegation.swift): the inheritance/super/final machinery Go lacks, value vs reference semantics, protocol-oriented defaults, generics vsanyvssome, subscripts/operators — closing with why composition beats inheritance anyway. - NIO server family: HTTP/1, TCP echo, WebSocket, UDP echo, chat
broadcast — real
MultiThreadedEventLoopGroupservers, self-testing, deterministic by happens-before rather than sleeps. - Testing tour: 52 tests mirroring docs.swift.org/documentation/testing
page by page (see
pkg/testing-tour).
Rules of the house
letby default; scripts, no ceremony; imports on demand.- Go concepts with no clean mapping are supplanted by the Swift-native
page (
inout, actors, cancellation, Swift Testing) — seeSKIPPED.md. - Third-party deps live only in the package chapter: swift-nio and swift-argument-parser, nothing else.