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.

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.

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 trial in the SwiftFairy app. No card or payment information is required.

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

Explore the other Scrolls