3. XCode: How to add a custom code snippet

Source: Internet
Author: User

We often define the property of some retain, and we will write about it like this every time:

@property (nonatomic, retain) Type *name;

Every time must be honest to "@property (nonatomic, retain)" Knock over again, this is too tired.

So can you like the code hint function of Xcode, each time we only need to hit two or three keys, the code hints come out, and then all of a sudden we can enter this code into? Isn't that a lot easier?

Don't worry, I'll take this code as an example to show you how to add a custom code snippet to Xcode.

    • Open or create a new item with Xcode, and then open a. h or. m file casually. &NBSP
    • Find a blank location, enter "@property (nonatomic, retain) < #type #> *< #name #>;". (without double quotes, "<#", "#>" The role of the two symbols, you will understand in a moment.  
    • Open the utilities View to the right of Xcode, and then locate and open the Code Snippets Library at the bottom of the map.  
    • Select the code that we just entered and drag it to the Codes Snippets library.
    • scrolls to the bottom of the Code Snippets Library and finds an icon with a "User" text above the curly braces.  
    • clicking that icon pops up a window. Then click the Edit button on the bottom left of the window
    • in the title and completion shortcut, enter the title and shortcut key for the snippet. Shortcut keys are used to activate code hints, and headings appear in code hints. In this example, we enter the title "Objective-c @property retain", and the shortcut key is "@property".
    • Select the corresponding platform, language, and completion scopes. Then click on the "Done" button.
      In this example, platform we choose All;language objective-c;completion Scope Select Class Interface Methods.
      Completion scope Specifies the valid areas of the shortcut keys for activating code hints, such as the class Interface methods that we have chosen to indicate that the shortcut key for this code activates the code hint in the area where the class method is declared, and in any other area, No matter how you hit the shortcut, there's no hint of this code.

OK, now delete the code we just entered. Then look for the header file of the class, and in defining the property's area, try typing the shortcut we just set. Did you notice? We just typed in the "@p" character, and the code hints are out. Check the code, enter, Xcode automatically give us the code to complete, is not much faster?

3. XCode: How to add a custom code snippet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.