SwiftTips
A collection of Swift tips & tricks that I've shared on Twitter
Install / Use
/learn @JohnSundell/SwiftTipsREADME
⚠️ This list is no longer being updated. For my latest Swift tips, checkout the "Tips" section on Swift by Sundell.
Swift tips & tricks ⚡️
One of the things I really love about Swift is how I keep finding interesting ways to use it in various situations, and when I do - I usually share them on Twitter. Here's a collection of all the tips & tricks that I've shared so far. Each entry has a link to the original tweet, if you want to respond with some feedback or question, which is always super welcome! 🚀
Also make sure to check out all of my other Swift content:
- 📖 My weekly articles, with a new post about Swift every Sunday!
- 🎧 My podcast which features special guests from around the community.
- 📬 My monthly newsletter - rounding up all of my content, including these tips, on the 1st of every month.
Table of contents
#102 Making async tests faster and more stable
#101 Adding support for Apple Pencil double-taps
#100 Combining values with functions
#99 Dependency injection using functions
#98 Using a custom exception handler
#97 Using type aliases to give semantic meaning to primitives
#96 Specializing protocols using constraints
#95 Unwrapping an optional or throwing an error
#94 Testing code that uses static APIs
#93 Matching multiple enum cases with associated values
#92 Multiline string literals
#91 Reducing sequences
#90 Avoiding manual Codable implementations
#89 Using feature flags instead of feature branches
#88 Lightweight data hierarchies using tuples
#87 The rule of threes
#86 Useful Codable extensions
#85 Using shared UserDefaults suites
#84 Custom UIView backing layers
#83 Auto-Equatable enums with associated values
#82 Defaults for associated types
#81 Creating a dedicated identifier type
#80 Assigning optional tuple members to variables
#79 Struct convenience initializers
#78 Usages of throwing functions
#77 Nested generic types
#76 Equatable & Hashable structures
#75 Conditional conformances
#74 Generic type aliases
#73 Parsing command line arguments using UserDefaults
#72 Using the & operator
#71 Capturing multiple values in mocks
#70 Reducing the need for mocks
#69 Using "then" as an external parameter label for closures
#68 Combining lazily evaluated sequences with the builder pattern
#67 Faster & more stable UI tests
#66 Accessing the clipboard from a Swift script
#65 Using tuples for view state
#64 Throwing tests and LocalizedError
#63 The difference between static and class properties
#62 Creating extensions with static factory methods
#61 Child view controller auto-resizing
#60 Using zip
#59 Defining custom option sets
#58 Using the where clause with associated types
#57 Using first class functions when iterating over a dictionary
#56 Calling instance methods as static functions
#55 Dropping suffixes from method names to support multiple arguments
#54 Constraining protocols to classes to ensure mutability
#53 String-based enums in string interpolation
#52 Expressively comparing a value with a list of candidates
#51 UIView bounds and transforms
#50 UIKit default arguments
#49 Avoiding Massive View Controllers
#48 Extending optionals
#47 Using where with for-loops
#46 Variable shadowing
#45 Using dot syntax for static properties and initializers
#44 Calling functions as closures with a tuple as parameters
#43 Enabling static dependency injection
#42 Type inference for lazy properties in Swift 4
#41 Converting Swift errors to NSError
#40 Making UIImage macOS compatible
#39 Internally mutable protocol-oriented APIs
#38 Switching on a set
#37 Adding the current locale to cache keys
#36 Setting up tests to avoid retain cycles with weak references
#35 Expressively matching a value against a list of candidates
#34 Organizing code using extensions
[#33 Using map to transform an optional into a Resu
Security Score
Audited on Mar 24, 2026
