One annotation. Instant plural type aliases. Zero runtime cost.
Flock is a Swift macro library that automatically synthesises a plural typealias for any named type. Annotate once with @Flock, and the compiler takes care of the rest.
@Flock struct User { var name: String }
@Flock struct City { var zip: String }
@Flock class Wolf {}
@Flock enum Status { case active, inactive }
// These are now valid, anywhere in your module:
let users: Users = [] // typealias Users = [User]
let cities: Cities = [] // typealias Cities = [City]
let wolves: Wolves = [] // typealias Wolves = [Wolf]
let statuses: Statuses = [] // typealias Statuses = [Status]No code generation scripts. No build-phase hacks. Just Swift macros, exactly as Apple intended.
Writing typealias Users = [User] by hand is harmless once. After the twentieth time it becomes noise β a boilerplate tax on every new model type. Flock eliminates it entirely, keeps your code DRY, and stays completely invisible to anyone reading the generated binary.
| Minimum | |
|---|---|
| Swift | 5.9 |
| Xcode | 15 |
| macOS | 13 Ventura |
| iOS / tvOS | 16 |
| watchOS | 9 |
| visionOS | 1 |
Add Flock as a dependency in your Package.swift:
dependencies: [
.package(url: "https://github.com/YOUR_USERNAME/Flock.git", from: "1.0.0"),
],Then add "Flock" to your target's dependencies:
.target(
name: "MyApp",
dependencies: ["Flock"]
),File β Add Package Dependenciesβ¦ and paste the repository URL.
Import Flock and annotate any struct, class, enum, or actor:
import Flock
@Flock struct Article {
var id: UUID
var title: String
var body: String
}
// Now available everywhere Article is visible:
func render(_ articles: Articles) { β¦ }
let feed: Articles = fetchArticles()The @Flock macro expands into a single peer declaration:
// You write:
@Flock struct Article { β¦ }
// Compiler sees:
struct Article { β¦ }
public typealias Articles = [Article]Nothing else. No conformances, no wrappers, no surprise behaviour.
Flock's built-in engine covers the most common English morphological patterns:
| Category | Example |
|---|---|
| Regular | User β Users |
| Consonant + y | City β Cities |
| Vowel + y | Day β Days |
| Sibilants (-s, -x, -sh, -ch) | Class β Classes, Box β Boxes |
| f / fe β ves | Wolf β Wolves, Knife β Knives |
| Latin -um | Medium β Media |
| Latin -us | Cactus β Cacti |
| Latin -is | Analysis β Analyses |
| Greek -on | Criterion β Criteria |
| Irregular | Person β People, Child β Children |
| Invariant | Fish β Fish, Sheep β Sheep |
Unknown words receive a simple -s suffix β a safe, predictable fallback.
- Custom plural override:
@Flock("Statuses")for edge cases - French and Spanish pluralisation modes
- Swift Package Index badge integration
- DocC documentation site
Pull requests are welcome! When adding new pluralisation rules, please add a corresponding test case in FlockTests.swift.
git clone https://github.com/YOUR_USERNAME/Flock.git
cd Flock
swift test
Flock is released under the MIT License. See LICENSE for details.