Xcode Tips

#41 We can add link to functions in Xcode’s documentation using the format ``Class\function``

#40 Shift+Command+A in the iOS simulator is a convenient way for verifying dark and light appearances

#39 While refactoring, it is convenient to use the Xcode’s feature of double-clicking on a curly brace selects the whole code block.

#38 Xcode offers code generation for adding or replacing a completion handler based function with an async function (right click > Refactor > Convert Function to Async / Add Async Alternative / Add Async Wrapper).

#37 Xcode 15 brings a support for bookmarking source code. We can bookmark files or specific lines.

#36 Xcode 15 has a quick action picker which can be triggered with Shift+Command+A. So much easier to discover different actions!

#35 Xcode 15 comes with a live documentation preview, and it sure is handy to see how the generated documentations looks like immediately. Can be enabled with choosing Editor > Assistant > Documentation Preview.

#34 Xcode allows simulating different conditions when connecting a device, navigating to Window > Devices and Simulators > Devices. Makes it easy to simulate tough network conditions, thermal states or GPU states.

#33 Enabling RUN_DOCUMENTATION_COMPILER build setting in Xcode updates the project’s documentation in the developer documentation window with each build.

#32 Xcode has a Development Assets setting which defines a path to assets or code which should be only available in debug builds. For example, this opens up using additional images or anything like JSON data for creating rich SwiftUI previews.

#31 Additional concurrency checks can be enabled for async-await Swift code by adding “-Xfrontend -warn-concurrency -enable-actor-data-race-checks” to Other Swift Flags in Xcode.

#30 Product > Perform Action > Build With Timing Summary builds your project and reveals a summary under the View > Navigators > Reports > last build action. Make sure to select the “Recent” filter for revealing it. Can be insightful.

#29 SwiftUI previews can be reset if they fail to recover

xcrun simctl --set previews delete all

#28 Resolving packages with command line is much more reliable compared to using Xcode. Especially when a project has more than 10 remote packages, then Xcode struggles a lot.

xcodebuild -resolvePackageDependencies -project path-to-xcodeproj -scmProvider system

#27 Xcode’s Editor menu contains Create Preview and Create Library Item menu items which inserts a template

#26 shift+command+[ or ] switches between tabs in Xcode. Very useful when working with numerous tabs.

#25 control+option+command+\ searches selected text or text where the caret is in the documentation window. Really useful to quickly look up a symbol.

#24 Xcode can build and show documentation for any project in the Developer Documentation window.

#23 Re-running tests which ran last time quickly with control+option+command+G. Such a time saver when writing new tests.

#22 Sort files and folders by name by right-clicking on a folder and selecting “Sort By Name”

#21 Autocomplete switch statement with control+option+command+f (Fix all issues). Requires writing “switch variable {}” and then it adds all the cases.

#20 Add tests file to the Counterparts menu and use control+command+up/down arrow to jump from the implementation file to the tests file. defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "Tests"

#19 Clear Xcode caches and SDKs with the System Information app:  > About this Mac > Storage > Developer

#18 Keep simulator list short by deleting simulators you do not need. Window -> Devices and Simulators

#17 Fix all issues with control+option+command+f keyboard shortcut. Especially useful for adding required methods when conforming to protocols.

#16 Speed up Xcode UI tests by disabling UI animations and increasing layer speed.

#15 Self._printChanges() prints out the property which triggered the body reload in Xcode 13.

#14 Use MARK, TODO, and FIXME keywords for structuring the jump bar

#13 Instruments has a deferred recording mode which is helpful for saving CPU in resource hungry situations

#12 Simulator can record screen in Xcode 12.5. Use command+R for starting the screen recording.

#11 If you want to avoid validate settings warnings after upgrading to a new Xcode version, then bump the version value of “LastUpgradeCheck” in your MyProject.xcodeproj/project.pbxproj file

#10 Show only recent files and show only files with source control status filters in the project navigator can make it easier to jump between same files or reviewing changed files in larger projects.

#9 Move the current line or selection up and down: option+command+[ or option+command+]

#8 Check spelling by running spell-checker on your code: command+;

#7 Use “Run Without Building” (ctrl+cmd+r) when you just need to relaunch the app. Many seconds saved and especially useful while debugging.

#6 Using Xcode behaviour for opening a debugging tab

#5 Committing Xcode breakpoints to git

#4 Building a Swift package for iOS: xcodebuild -scheme IndexedDataStore -destination 'platform=iOS Simulator,OS=latest,name=iPhone 11 Pro'

#3 Show build time in Xcode toolbar: defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES

#2 Quick way to capture a demo video from iOS simulator using a command line: xcrun simctl io booted recordVideo -codec h264 demo.mpf -f

#1 Build warnings for catching slow type checking in debug builds. Add “-Xfrontend -warn-long-expression-type-checking=<milliseconds>” to Other Swift Flags for debug builds.