Write Swift Booleans Like a Pro: Clean Code Guide
Boolean Naming Best Practices Cheatsheet for Cleaner Swift Code

Search for a command to run...
Boolean Naming Best Practices Cheatsheet for Cleaner Swift Code

No comments yet. Be the first to comment.
How to upgrade your SwiftUI apps from ObservableObject to the @Observable macro. Reduce boilerplate and improve performance.

Master the fundamentals of app store algorithms. Learn the exact character limits, indexing rules, and ranking timelines for Apple and Google.

Master Brand Defense and Generic Offense to scale your app discovery.

A guide to writing cleaner, more maintainable, and scalable Swift code using SOLID principles.

The ultimate ASO dictionary. Decode key concepts like semantic cores, traffic types, and conversion rates to build a winning app strategy.

Ever stared at your code and thought, “Who wrote this mess?” ...and it was you? We've all been there.
Clean code isn’t just about satisfying the compiler. It’s about writing something your future self and your team won’t dread revisiting. One easy win? Start by naming your boolean variables right.
This blog focuses on Swift, but these naming principles apply to any language.
As iOS developers, we spend a lot of time dealing with logic and states. Yet sometimes, our code reads more like cryptic commands than understandable sentences.
Like Steve Jobs once said:
“Simple can be harder than complex. You have to work hard to get your thinking clean to make it simple.”
So let’s simplify and make our code cleaner by prefixing booleans like we mean it.
Here’s a quick rulebook I follow and it works not just for Swift, but pretty much any language:
is — For statesUse is when you're expressing the current state of something.
Bad:
if active { ... }
Good:
if isActive { ... }
Now it reads like English. Is active?
has — For ownership or possessionUse has when referring to something your object holds or owns.
Bad:
if subscription { ... }
Good:
if hasSubscription { ... }
Does it have a subscription?
should — For expectations or conditionsUse should to indicate what ought to happen next.
Bad:
if retry { ... }
Good:
if shouldRetry { ... }
We’re no longer wondering if "retry" is a flag, a method, or a mood. It’s an expectation, and it tells us clearly what to do.
can — For capabilitiesUse can when referring to permissions or abilities.
Bad:
if edit { ... }
Good:
if canEdit { ... }
It’s not just about editing, it’s about whether the user can edit. Huge difference in clarity.
A good rule of thumb: your if statements should read like a sentence:
if user.canEdit && user.hasSubscription && !user.isBlocked {
showEditor()
}
Clean, understandable, and super readable, even for someone new to the codebase.
Writing clean code is a habit, not a plugin. These boolean prefixes may seem small, but they can dramatically improve the readability and maintainability of your code, especially when working in teams or revisiting old projects.
Swift is beautiful. Let’s write like it.