2

Little big improvements in Xcode 15

 1 year ago
source link: https://sarunw.com/posts/little-big-improvements-xcode15/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Xcode 15 gets a lot of nice improvements in WWDC 2023. In this article, I will briefly introduce you to some that I find interesting.

Methods with many default parameters

Last year in Xcode 14, we got a way to select parameters using fuzzy search.

But it is quite hard and error-prone for methods with many parameters with similar names, e.g., the frame modifier.

In Xcode 14, you can select parameters which match the search term.

In Xcode 14, you can select parameters which match the search term.

This year, you can navigate to all possible combinations of those parameters by pressing the right arrow key →. You can browse them using the up and down arrow key.

  1. Press the right arrow key → to expand the options.
  2. Then, use the up and down arrow to navigate.
Expand all possible combination of parameters.

Expand all possible combination of parameters.

This technique also works with fuzzy search.

In the following example, we search for the "framemax". Once we press the right arrow, Xcode will show only combinations that contain the word "max".

Work with fuzzy search.

Work with fuzzy search.

You can easily support sarunw.com by checking out this sponsor.

Turn your code into a snapshot:

Sponsor sarunw.com and reach thousands of iOS developers.

Context awareness

Code completion and suggestion are smarter across the board.

For example, Xcode can suggest a class or struct name that matches the file name.

Xcode suggests a symbol name based on the file name.

Xcode suggests a symbol name based on the file name.

Completions also got better context awareness. It can give you better suggestions based on where you initiated the suggestion.

When trying to add a modifier to a Text view, it shows modifiers related to Text, e.g., font and bold.

Xcode suggests modifiers related to a Text view.

Xcode suggests modifiers related to a Text view.

If you try this on an image view, you will be suggested with resizable and renderingMode.

Xcode suggests modifiers related to an image view.

Xcode suggests modifiers related to an image view.

On a VStack, it would show padding, which is the most frequently used modifier for this view.

Xcode suggests modifiers related to a VStack.

Xcode suggests modifiers related to a VStack.

It is also smart enough not to suggest the same modifier twice. In Xcode 14, you might be suggested to use the .font modifier twice.

Xcode 14 vs. Xcode 15.

Xcode 14 vs. Xcode 15.

Documentation Preview

Xcode use markdown-flavored markup syntax for code documentation.

In Xcode 15, we got a "Documentation Preview" assistant, which will show a rendered version of your document.

You can preview your document in real time and ensure it looks like what you expected.

To use it, open the Assistant panel in either one of three ways:

  1. Editor menu > Assistant.
  2. Shortcut ⌃ – Control + ⌥ – option + ⌘ - command + ⏎ Return.
  3. Choose "Editor icon", then "Assistant".
little-big-improvements-xcode15-editor-icon.png

Once you open the Assistant panel, select "Documentation Preview" from the jump bar.

Select

Select "Documentation Preview" from the jump bar.

Then you can see the preview of your editing documentation update in real time.

Documentation preview update in real-time.

Documentation preview update in real-time.

Quick Action

This might be my favorite feature in Xcode 15.

You can think of Quick Action as Command Palette that you usually see in other editors (the one with command + K).

Quick Action lets you access all of Xcode's menu options.

You can use it by pressing Command ⌘ - command + ⇧ - shift + A.

With all new features added to Xcode every year, at some point, you wouldn't be able to remember them or run out of key bindings. This Quick Action would be your savior.

In this example, I use it to create a Swift file and generate a memberwise initializer.

Quick Action.

Quick Action.

I don't need to move a mouse, remember shortcuts, or find commands in the context menu. Love it.

Bookmark

Xcode 15 introduces a Bookmark.

You can use a bookmark to annotate a specific line of code or symbol in your code so you can quickly return to it later.

To add a bookmark:

  1. Right-click on the line of code that you want to bookmark.
  2. Select "Bookmark" from the context menu.

You can use Quick Action to add a bookmark.

Right-click on the line of code that you want to bookmark.

Right-click on the line of code that you want to bookmark.

To get back to your bookmarks:

  1. Open the new "Bookmark Navigator", the third tab in the Navigation pane.
  2. You can either click it or use shortcut ⌘ - command + 3.
  3. You can see all bookmarks in your project there.

Bookmark NavigatorBookmark Navigator

You can easily support sarunw.com by checking out this sponsor.

Turn your code into a snapshot:

Sponsor sarunw.com and reach thousands of iOS developers.

Format to multiple lines

Xcode 15 also adds a new refactor command that turns a line of multiple parameters into multiple lines.

This is very helpful for methods with many parameters.

To use this new refactor command:

  1. Move the cursor in the parameter list you want to format (between open and closed parentheses).
  2. Right-click and select "Refactor" > "Format to Multiple Lines".

You can use Quick Action to do this.

Format to multiple lines

Format to multiple lines


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK