27

Recently when I was using Xcode 10 beta 3, I tried to make a code snippet and add it to the code snippet library.

But the drag drop cannot be done as the code snippet library is detached in Xcode 10, and hides when I click on a code.

How to add code snippet in code snippet library in Xcode 10?

3 Answers 3

61

After some time found out.

Select the code you want to add to library. Right-click on it and click on Create Code Snippet from the pop-up menu.

Apparently upto Xcode 9.x.x, this option was not there.

enter image description here

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

3 Comments

To edit snippet open snippet bar (curly braces button), click once on snippet and wait a bit.
@Sugar perfect, tnx
Just in case. To add a placeholder to code snippet, add <# some_placeholder #> text.
6

For Xcode 10 to make a Snippet,

1) Select the resign of code you want to reuse in future.

2) Click the right button.

3) In the context menu, select "Create Code Snippet". The Snippet Library will appear with a new snippet created.

Comments

5

to create a snippet you can do it in the following way:

  1. menu editor and select Create Code Snippet:

Create Code Snippet

  1. In the box that appears, fill all the information of your snippet: enter image description here

if you want your variables to be highlighted in gray you have to surround the variable in the following way, <# name #>:

example:

public let <#name#>: <#type#>

Comments

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.