How to save your own block of code in Xcode

Source: Internet
Author: User

In the process of developing iOS, Xcode is definitely the most used tool, not one of them. Because Apple's official offer on this platform, although no competitor, but adhering to Apple's consistent attention to detail principles, Xcode is a pretty good IDE.

As an iOS development siege Lion, you definitely need to remember a lot of Apple's API, enough to make you crash. And now the trend of the API is more and more long, no longer entangled in as short as possible. So here's the question, although there's a hint for the code, but you have to remember at least a few letters at the beginning? Do you have a blank mind, basically do not remember the situation?

For example, if I want to access the Readme.txt file under the bundle, the code is as follows:

  Nsarray *path = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);  return [[Path objectatindex:0] stringbyappendingpathcomponent:@ "Read.txt"];

This is a rarely used API, the ashes of the veteran can start typing in the slightest, and then the code to complete-fast and good, and for some novice, you need to go to the manual search or other places copy code come over.

Fortunately, Apple has taken this into account for us, so it provides a function to expand the code block in Xcode. We can see the CodeSnippets Library in the utilities panel of Xcode, where Apple has prepared a lot of templates, you can easily pull into the code, this code will appear in the code, you just need to fill in the relevant parameters on everything OK.

Here you can imagine, if our code block can also join this library, everything is perfect. Bingo, Apple also thought of this, and gave the answer! The method is also super simple--check the code into the codesnippets inside a drag on the line!

We can see that an automatic addition of my Code snippet item is also very intimate to a user callout, click on the details will appear, click the Edit button can also be edited.

The content that can be edited includes name, Introduction, shortcut, and so on. The completion shortcut on the diagram is a shortcut, and if you're used to doing everything with the keyboard, this setting can be very useful.

Here the ointment is to write dead Readme.txt, we can not always access this particular file, so the best way to write is to leave a parameter, let the user to fill out.

I used a copy of the system API inside a parameter put, also can use, do not know if you want to type, should be typing what content, which Daniel know please reply, first thanks.

Once you have completed these settings, you can click on the Done button and the code will be in Xcode, and you can use it whenever you want.





How to save your own block of code in Xcode

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.