In the process of doing project development, is actually more troublesome, because the same content, we need to write many times, virtually to our development to increase the workload. So is there any way to avoid this repetitive workload? That's what we're going to say here.
In project development, we can often see the following code:
- @property (nonatomic, copy) NSString *isbatchapprove;
- @property (nonatomic, copy) NSString *currentresult;
- @property (nonatomic, copy) NSString *strversion;
- @property (nonatomic, copy) NSString *operatetype;
At first glance, no problem, but in the process of doing project development, is actually more troublesome, because the same content as shown below, we need to write many times, virtually to our development increased workload. So is there any way to avoid this repetitive workload? This is the code Snippets Library to be said here.
- @property (nonatomic, copy) NSString
What is Code Snippets
In fact, in the process of project development, we have enjoyed the convenience of code Snippets many times, as shown in:
When we enter the SW, it will automatically appear in the back of so much content, click the Enter key, the content is automatically written. This is code Snippets, which is designed to enable programmers to enter frequently used code snippets at the fastest speed and improve programming efficiency. This feature has been introduced from XCODE4, where we can set the display code Snippets as follows:
After setting up the display, we can see Code Snippet, which has a lot of xcode snippets in it, and the switch in the example above is one of them. Double click on a specific code Snippet, you can see the code Snippet details, click the Edit button, you can see more content (new code Snippet when introduced)
How to create a new code Snippets
From the above introduction, for the code snippets benefits, we should be very clear. Once you're clear, you'll have a question: Can you create a new code snippets in Xcode? The answer is yes, below we will introduce the creation of the property in the introduction, step by step the code snippets created process.
The first step: Write code Snippets. Write the following statement where the @property attribute is declared:
- @property (nonatomic, copy) nsstring *< #name #>;
Above < #name the effect of #>, can be known in the later use effect.
Step Two: Create a new code Snippets. Select the statement written in the first step, drag the left mouse button to the code Snippets indicated in the area of Xcode, and create a new code Snippets. The effect after the new is as follows:
"Property description"
- Title of the 1.title:code snippets;
- 2.summary:code snippets's descriptive text;
- 3.Platform: can use code snippets platform, have Ios/os x/all three options
- 4.Language: In which languages you can use the Code Snippets
- 5.Completion Shortcut:code snippets shortcuts, such as the second part of this article to write the switch code snippet to use the SW, here, the property set the shortcut to the PC
- 6.Completion Scopes: Which files can be used in the current code Snippets, such as all locations, the header file is medium, of course, you can add multiple supported locations.
- 7. The last large empty area is a preview of the effect of code snippets.
When everything is set up, click the Done button in the lower right corner of the menu and the new job is finished.
Code Snippets the Use
We have two ways to use code Snippets, or just the example of a newly defined PC Property Code Snippets:
Mode one: in the appropriate position (because you can set the use platform, use the language, use the file and other restrictions when defining the code snippet), enter the PC, you can pop up the following prompt box.
Click Enter to see the following code:
Mode two: Directly in the Code Snippets section to find the code Snippets we need to use the left mouse button to drag the code Snippets to the appropriate location.
Code Snippets of Backup
The code snippets in Xcode is placed by default in the following directory:
- ~/library/developer/xcode/userdata/codesnippets
We can either back up the code snippets in the directory or copy it directly to a different computer, so there is no pressure to collaborate with multiple computers.
Code Snippets commonly used in project development
Here are some of the snippet that I used frequently in my project, for reference only.
1.Notification add: Adds a notification.
2.Notification Remove: Remove notifications.
3.Notification Post: Publish Notifications.
The properties of the 4.Property copy:nsstring type.
5.Property Retain:retain property.
6 ... follow the path of nature and touch the heart of the impetuous
xcode-Programming Tips-code Snippets Library