What is Code Snippet and how to create your own in Xcode ?



1. What is Code Snippet?


-> Code Snippet is nothing but it is a block of Code that you can reuse in your Xcode any where any time. It is locally saved in your Xcode.

-> When you are in any UIViewController or any File than you must type so it shows matching suggestions. Suggestions under {} or demoted by icon {} is nothing but it is Code Snippet which is already created by Apple Developer Team for Xcode. When we start typing, Xcode opens up a Context Poup and Displays matching suggestions.
eg: typing print

Code Snippet

-> Suggestion shows in the form of some icons so we have to understand the meaning of all those icons


 ‘{}’ shows that it is a code snippet.


 ‘M’ shows that it is a method.


 ‘f’ tells that its a c or c++ function.


 ‘C’ shows that its some constant


 ‘V’ is for variable.


 ‘T’ stands for a data type.


 

2. How to create your own Code Snippet.

-> It is very easy to create your own code snippet in Xcode. Just follow my Steps 

Step1) Go to your Xcode and open any .swift file.

Step 2) Write your code which you wants to save as Code Snippet.




Step3) Now Select the code which you wants to save.




Step4) Now, On selected code Click Right button on mouse. now here we go. you will have some options.



Step5) Click on        Create Code Snippet       



Step6) Now, give some Title and Summary of your code Snippet. On bottom select Language, Platform if you wants. Hit on Done Button.

Step7) Once you Done. Now you are ready to go. you can use your Code Snippet. And anytime you can Edit and Delete your Code Snippet.

NOTE:-  Every Code Snippet name must be a Unique.

3. How to see your own code snippet which you created.

Step1) Go to Xcode
Step2) Click on + button from Top Right corner. or you can use Short Key (Windows + Shift + L) or (Command + Shift + L)



NOTE:-  Remember that you must not be in any Storyboard. you must be in any Swift File.

Step3) Here is your Code Snippet. You must be in tab of {}






THANK YOU




Comments

Post a Comment