NEW Tool! SwiftFairy: Local Swift and SwiftUI code reviews for your coding agent. Learn more ...NEW Tool! SwiftFairy:Local code reviews for your agents. Learn more...
← All SwiftFairy Scrolls

SwiftFairy Scroll

Modern Swift

Refine code for clarity, maintainability, and performance through idiomatic use of modern Swift APIs, including modern Swift concurrency and collection processing.

What your agent can improve

Idiomatic APIs

Help your agent choose language features and APIs that express the code's intent more clearly.

Modern Swift concurrency

Give your agent guidance on concurrency API choices and how to apply modern Swift conventions.

Collection processing

Identify incorrect indexing and unnecessary processing so your agent can work with collections more safely and efficiently.

Issues Modern Swift flags

Modern Swift flags over 60 issues in your code. Each finding arrives at the line where the issue occurs, with the guidance and code example written for that case.

  • filter followed by count where count(where:) would do
  • Thread-blocking sleeps and dispatch queues in async code
  • Sequential awaits that could start together with async let
  • Long-running loops that never check for cancellation
  • Combine publishers consumed from async code
  • CommonCrypto calls that CryptoKit replaces
  • Sorting or shuffling a whole collection to take a few elements
  • Flags and nested conditions that a tuple switch or labeled break expresses
  • Hand-written helpers that Algorithms or AsyncAlgorithms already provide
  • if let x = x where shorthand optional binding applies
Alone SwiftFairy

Token efficiency

Your agent skips millions of tokens of reasoning and reads guidance only for the issues flagged.

Deep knowledge

Built on our books and articles, and Natalia's work on Apple's SwiftUI team.

Example findings

These examples show the patterns SwiftFairy flags and the guidance your agent can use to address them. Highlighted lines mark the code to review; each finding indicates whether the guidance is a requirement, recommendation, or consideration.

Should

Count matches without building an array

When only the number of matching elements is needed, filtering an array creates an unnecessary intermediate array. count(where:) counts the matches directly.

Pattern flagged for review

let temperatures = [-5, 10, -2, 20, 25, -1]

let warmDays = temperatures.filter {
     $0 > 0
}.count

A possible improvement

let temperatures = [-5, 10, -2, 20, 25, -1]

let warmDays = temperatures.count {
     $0 > 0
}

count(where:) returns the same result without allocating an intermediate array. It requires a Swift 6 compiler.

Consider

Exit nested loops without a flag

When finding a result should end both nested loops, a labeled break can exit the outer loop directly. This avoids a flag whose only purpose is to communicate that the search has finished.

Pattern flagged for review

var stop = false
for row in matrix {
     for value in row {
         if value == 5 {
             print(value)
             stop = true
             break
         }
     }
     if stop {
         break
     }
}

A possible improvement

search: for row in matrix {
     for value in row {
         if value == 5 {
             print(value)
             break search
         }
     }
}

The labelled break exits both loops without temporary state. Use it when the flag has no other purpose and exiting directly preserves the work performed before leaving the loops.

…and over 60 other issues.

Put the findings to work

Ask your agent to review a code change or a complete codebase with SwiftFairy. Your agent uses the findings and their accompanying code examples to resolve issues in your code.

How to use SwiftFairy

Try Modern Swift free for one day

Activate your free trial within the app at any time.

Choose lifetime access, a fixed term, or a subscription for this Scroll, or get all four together in a bundle.

Explore the other Scrolls