-1

I am new to Swift and also Xcode. In many tutorials I can see that snippets are really usefull especially for the beginners like me. Unfortunately I cant use them. When I am typing something, for example iforfor, nothing shows up in the autocomplete section. Or if it does (like for struct`) when I hit enter it just autocompletes my word.

I want it to look like this:

enter image description here

Instead, it just autocompletes:

enter image description here

if, for, etc. doen't even show up in autocomplete.

enter image description here

I couldn`t find a solution. Any help would be really useful.

I basicly want it to work like this https://sarunw.com/posts/how-to-create-code-snippets-in-xcode/#using-xcode-snippets

1
  • Is the availability of your snippet set to All Scopes? Commented Apr 4, 2023 at 22:27

1 Answer 1

0

First, make sure the proper settings are enabled in Xcode. Go to Xcode -> Preferences (or Settings depending on your version of macOS). Then select the "Text Editing" tab. Then select the "Editing" sub-tab. Ensure the "Suggest completions while typing" option is enabled.


While typing in Xcode, begin typing the struct keyword but don't press return. You should see the following:

enter image description here

By selecting the "struct - Struct" choice from the menu, you will end up with desired code block snippet.

This also works when you want to add a code snippet for an if statement. Begin by typing if (make sure you are entering this in a valid context for an if block). Xcode will display appropriate choices:

enter image description here

Selecting, for example, the "if - If Statement" choice from the menu will leave you with an appropriate snippet:

enter image description here

Similar snippets are available for various statements such as for and while, etc.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your answer. I have checked my settings "Suggest completions while typing" option was enabled, I have disabled it and enabled again. Now it works perfectly for "struct" or "func" but for if only the one with dot shows up.
Found it also for if statement! I needed to scroll down a lot. Thank you once again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.