One of the most important parts of writing code is writing maintainable code. In a group setting especially, a style guide is very important. Lint tools help to enforce that (as well as checking for certain types of bugs). SwiftLint is a lint tool that is based on GitHub's Swift Style Guide.
Install it with Homebrew:
brew install swiftlint
There are 2 ways to use it, either A) run it from the shell, which will examine Swift code files in the current directory:
swiftlint
Or B) Add a Run Script Phase
:
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
As with all things Swift, it's a relatively new tool and it implements 31 rules as of writing.
There are more options such as using the autocorrect
option and more, described in the README.
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.
Here's a few related nuggets:
- iOS Dev Nugget 314 Checked Array Subscripting
- iOS Dev Nugget 310 Weak Reference Wrapper Class
- iOS Dev Nugget 308 Careful with early return statements in functions that return void
- iOS Dev Nugget 307 Array Out of Bounds
- iOS Dev Nugget 306 Underscores in Numeric Literals
- iOS Dev Nugget 305 Declaring Distinct Types from General Types
- iOS Dev Nugget 303 Use Enums for States
- iOS Dev Nugget 302 Realm
- iOS Dev Nugget 301 Print App Document Path II
- iOS Dev Nugget 300 Pipe Operator
- iOS Dev Nugget 295 SwifterSwift
- iOS Dev Nugget 293 iOSSnapshotTestCase (was FBSnapshotTestCase)
- iOS Dev Nugget 292 for-where
- iOS Dev Nugget 291 Implicit Member Expressions
- iOS Dev Nugget 287 Modifying a Property Which is a Struct Triggers didSet
- iOS Dev Nugget 283 Eureka for Forms
- iOS Dev Nugget 281 Use R.swift for Static References to Resources Like Images
- iOS Dev Nugget 280 Using Custom Fonts Without Updating Info.plist Manually
- iOS Dev Nugget 269 Including Finger Touches in App Preview Videos
- iOS Dev Nugget 265 value type cannot have a stored property that recursively contains it
- iOS Dev Nugget 257 Asserts
- iOS Dev Nugget 251 Retrieving the Current View Controller
- iOS Dev Nugget 248 In-app Native Routing
- iOS Dev Nugget 246 Mapping Swift and Obj-C Method Names
- iOS Dev Nugget 244 IteratorProtocol
- iOS Dev Nugget 241 Swift Enums with Labels
- iOS Dev Nugget 240 Print an Object's Unique Identifier
- iOS Dev Nugget 238 Keep Code in Method at the Same Level of Abstraction
- iOS Dev Nugget 234 #available and @available
- iOS Dev Nugget 229 Promises
- iOS Dev Nugget 228 Recording and Playing Back Network Calls
- iOS Dev Nugget 224 Lazy Collections
- iOS Dev Nugget 215 dump Instead of print for Swift Structs
- iOS Dev Nugget 211 Higher Order Functions: map, filter, reduce
- iOS Dev Nugget 210 PMAlertController
- iOS Dev Nugget 209 Swift Defer
- iOS Dev Nugget 207 Swift Nil-Coalescing Operator
- iOS Dev Nugget 206 Date doesRelativeDateFormatting
- iOS Dev Nugget 205 The Never Return Type in Swift
- iOS Dev Nugget 204 Swift @autoclosure
- iOS Dev Nugget 203 Swift Measurement
- iOS Dev Nugget 202 Swift Enumerations to Encode States
- iOS Dev Nugget 201 Swift Pattern Matching
- iOS Dev Nugget 200 Swift flatMap
- iOS Dev Nugget 199 Swift Talk Video Series
- iOS Dev Nugget 198 KZPlayground
- iOS Dev Nugget 197 App Initialization Code
- iOS Dev Nugget 196 Rename Refactoring for Swift Code
- iOS Dev Nugget 193 Result Enumeration
- iOS Dev Nugget 190 Quick Look Plug-in for Mobile Provisioning Files
- iOS Dev Nugget 189 Xcode's Fix All in Scope
- iOS Dev Nugget 187 Creating a Singleton Class in Swift
- iOS Dev Nugget 186 Injection for Xcode
- iOS Dev Nugget 185 Disabling Content Change Animation in CATextLayer
- iOS Dev Nugget 184 Async Library
- iOS Dev Nugget 183 Quality of Service Classes
- iOS Dev Nugget 182 Tracking the swift-evolution Git Repository
- iOS Dev Nugget 181 Swift Selectors
- iOS Dev Nugget 180 Low Power Mode
- iOS Dev Nugget 177 Push Notifications Testing During Development
- iOS Dev Nugget 176 Git no-commit Pre-commit Hook
- iOS Dev Nugget 175 Displaying a Popover in iPhone App
- iOS Dev Nugget 174 View Controller Containment to Avoid Growing a Fat View Controller Base Class
- iOS Dev Nugget 172 Print App Document Path
- iOS Dev Nugget 168 Using Blocks to Manage Contexts
- iOS Dev Nugget 161 Read Smalltalk Best Practice Patterns
- iOS Dev Nugget 158 Checking if Newer APIs Are Available In Older iOS Versions (II)
- iOS Dev Nugget 151 More Wrappers for Keychain Access
- iOS Dev Nugget 149 Timepiece, a Swift Library for Handling Dates
- iOS Dev Nugget 146 UIStackView and TZStackView
- iOS Dev Nugget 145 Listing Available Fonts
- iOS Dev Nugget 143 Don't Forget SQLite
- iOS Dev Nugget 142 Grand Central Dispatch
- iOS Dev Nugget 141 Great Swift Standard Library Examples Covered in Playground (Swift 2.0)
- iOS Dev Nugget 139 Custom Build Configurations and Xcode Subprojects
- iOS Dev Nugget 138 Interoperability: Using Enumerations Defined In Objective-C from Swift
- iOS Dev Nugget 137 Named Tuple Elements
- iOS Dev Nugget 136 Auto Layout with Cartography
- iOS Dev Nugget 135 CAShapeLayer, Animated Views and XCPShowView()
- iOS Dev Nugget 133 Dollar.swift
- iOS Dev Nugget 132 XCPCaptureValue in Swift Playgrounds
- iOS Dev Nugget 131 Running Asynchronous Code in Swift Playgrounds
- iOS Dev Nugget 129 Browsing the Swift Standard Library
- iOS Dev Nugget 124 performSelector:withObject:afterDelay: in Swift
- iOS Dev Nugget 123 Using dynamicType in Swift
- iOS Dev Nugget 121 InflectorKit
- iOS Dev Nugget 116 method() is unavailable: use object construction Class()
- iOS Dev Nugget 115 Displaying Information in Settings App
- iOS Dev Nugget 114 Preview an Image for Debugging
- iOS Dev Nugget 113 GPUImage, a GPU-based Image and Video Processing Framework
- iOS Dev Nugget 85 A More Customizable Button For Different States
- iOS Dev Nugget 81 TMCache For In-Memory and Disk-backed Caching
- iOS Dev Nugget 79 TweetBot Photo Flicking Effect
- iOS Dev Nugget 73 Open Source Date Picker from Square
- iOS Dev Nugget 71 Tap
- iOS Dev Nugget 68 Custom URL Schemes Directory
- iOS Dev Nugget 62 Using PDF Instead of PNG Files for Resizable Assets
- iOS Dev Nugget 49 Wrapper to Get UIColor Components
- iOS Dev Nugget 32 FMDB: Thin Objective C Wrapper Around SQLite
- iOS Dev Nugget 1 Easy logging of values and objects
.