Skip to content

killianmathias/Flock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐦 Flock

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.


Why Flock?

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.


Requirements

Minimum
Swift 5.9
Xcode 15
macOS 13 Ventura
iOS / tvOS 16
watchOS 9
visionOS 1

Installation

Swift Package Manager

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"]
),

Xcode

File β†’ Add Package Dependencies… and paste the repository URL.


Usage

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()

What gets generated?

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.


Pluralisation rules

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.


Roadmap

  • Custom plural override: @Flock("Statuses") for edge cases
  • French and Spanish pluralisation modes
  • Swift Package Index badge integration
  • DocC documentation site

Contributing

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

License

Flock is released under the MIT License. See LICENSE for details.

About

🐦 Swift macro that auto-generates plural type aliases β€” @Flock struct User {} β†’ typealias Users = [User]

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors