Paul Hudson’s Xcode Tips

December 14, 2020

Snippets

SwiftUI

Paul Hudson teaching an Xcode tip

For 25 days in December of 2020, Paul Hudson (@twostraws) tweeted out one Xcode tip per day (At 9:41 PM). Here’s everything I found useful with links to the related tweets.

  1. To auto-generate a memberwise initializer for a class, highlight the class name in the code, then go to Editor > Refactor > Generate Memberwise Initializer. Tweet Link
  2. While your app is running, you can click on the controls icon to bring up the Environment Overrides section. Here you can dynamically toggle settings such as dark mode, bold text, and high contrast mode. You can also toggle between light and dark mode in the simulator with the shortcut Shift + Cmd + A Tweet Link
  3. You can double click an opening or closing brace to select the entire block of code it contains. Tweet Link
  4. You can toggle Spell Check in the menu under Edit > Format > Spelling and Grammar > Check Spelling While Typing. Tweet Link
  5. You can batch fix all issues with Editor > Fix All Issues. Tweet Link
  6. When using Xcode’s Find Navigator (Shift + Cmd + F) and going through found instances, you can use the delete key to remove that instance from the list, which narrows down your found instances. Tweet Link
  7. Use the shortcut Option + Cmd + P to resume the preview. You can also use Option + Cmd + Return to hide and show the preview window. Tweet Link
  8. To split the screen between the simulator and Xcode, with the simulator active go to Window > Tile Window to Right of Screen. Tweet Link
  9. You can resize the window that pops up while Xcode tries to autocomplete by dragging the side of the window. Tweet Link
  10. To create a debugging breakpoint on the line your cursor is on, use the shortcut Cmd + \ or just click on the line number. You can remove a breakpoint by just dragging it off of the line numbers. Tweet Link
  11. To run your tests in a different order every time go to Product (Hold down Option) > Test. On the Info tab, click Options then check Randomize Execution Order. Tweet Link
  12. To navigate within a file quickly use the breadcrumbs at the top of the file. You can start typing to filter out the list that appears sort of like a mini-find menu. Tweet Link
  13. To get a quick overview of a file use Cmd + Ctl + Up. This will create a list of properties, method names, comments, and such. Press the shortcut again and you’ll get an overview of all the tests in a file. Tweet Link
  14. To create a documentation comment use Option + Cmd + / right above any method. Tweet Link
  15. To sort files within folders in the sidebar, right-click on any file group and choose “Sort By Name” to arrange them A-Z. Tweet Link
  16. To use source control in Xcode make sure you select the checkbox “Create Git repository on my Mac” when creating a new project or go to Source Control > New Git Repositories to create one in an existing project. Then go to Xcode > Preferences, click the Source Control Tab and make sure the “Show Source Control changes” checkbox is checked. Revision to lines will be shown beside the line numbers in blue tabs. Click them to view previous versions of that line. Tweet Link
  17. You can turn on the minimap by going to Editor > Minimap. Hover over the minimap and hold Cmd to reveal all the methods within the file. Tweet Link
  18. To re-run the previous test use the shortcut Ctrl + Cmd + Option + g. Tweet Link
  19. To set your own keyboard shortcuts go to Xcode > Preferences > Key Bindings tab. Tweet Link
  20. In Xcode’s “Find” menu you can click on each of breadcrumb-like texts (Find > Text > Containing) to bring up more options. You can also click on the search icon to see your recent searches. Tweet Link
  21. To properly indent pasted or copied code, select the code block and use the shortcut Cmd + I to properly indent it. Tweet Link
  22. You can test in-app purchases without App Store Connect. Make a new StoreKit Config File, and add your IAP. Now go to the Product menu, hold down Option, and click Run. From the Options tab of the window, change StoreKit Config, and now you’ll use the test IAP. Tweet Link
  23. To get documentation on any of the build settings Hold Option and double a setting to bring up a dialog with more information. You can also view this by having a build option selected and clicking on the question mark icon(Quick help inspector) in the right sidebar. Tweet Link
  24. You can pin previews to the Preview pane using the pin icon in the lower left. This will ensure that the preview remains in the pane even when switching to another View in the navigator. Tweet Link

@joekotlan on Twitter