Idiomatic APIs
Help your agent choose language features and APIs that express the code's intent more clearly.
SwiftFairy Scroll
Refine code for clarity, maintainability, and performance through idiomatic use of modern Swift APIs, including modern Swift concurrency and collection processing.
Help your agent choose language features and APIs that express the code's intent more clearly.
Give your agent guidance on concurrency API choices and how to apply modern Swift conventions.
Identify incorrect indexing and unnecessary processing so your agent can work with collections more safely and efficiently.
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
When only the number of matching elements is needed, filtering an array creates an unnecessary intermediate array. count(where:) counts the matches directly.
let temperatures = [-5, 10, -2, 20, 25, -1]
let warmDays = temperatures.filter {
$0 > 0
}.count
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
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.
var stop = false
for row in matrix {
for value in row {
if value == 5 {
print(value)
stop = true
break
}
}
if stop {
break
}
}
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.
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 SwiftFairyActivate 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.
Correct subtle bugs and performance issues in data flow, state ownership, and view updates by using SwiftUI as it was designed to be used.
Improve rendering and interaction performance by structuring charts and surrounding views to limit unnecessary updates and use Swift Charts APIs effectively.