DEV Community

Utku Y.
Utku Y.

Posted on • Edited on

4 2

XCode Code Snippet

Hi friends,

Here is a little trick for XCode beginners.

Have you ever wonder how you can improve your coding speed?
Here is a basic trick for speed up, code snippet.

For example you are developing an app with SwiftUI, actually it doesn't matter SwiftUI, Swift, Obj-c, etc. You can even use snippets as creating comment blocks.

Here are steps for creating snippets.

  1. Write block which will use as snippet
struct CodeSnippetDemo: View {
    var body: some View {
        Text("Hello, World!")
    }

    @ViewBuilder
    private func <#func name#>() -> some View {

    }
}

struct CodeSnippetDemo_Previews: PreviewProvider {
    static var previews: some View {
        CodeSnippetDemo()
    }
}
Enter fullscreen mode Exit fullscreen mode

screen shot of above code block

  1. Select whole block
  2. Then use menu as "Editor -> Create Code Snippet"
  3. You can change information as you want. Top block field is name of snippet. Below block is holding platform informations. Trick point is "Completion" field. Because when you type what you used in completion field, XCode will ask you to complete with "that" snippet.

snippet creation view

snippet completion example

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay