Xcode plug-in development-jttmagicline

Source: Internet
Author: User

The following articles are from my Evernote:Https://app.yinxiang.com/shard/s32/sh/86ab7ac1-7507-4c24-bf71-47e3c3f3c217/324316d417864a09dcce657b3b919b8aIf you want to view the native format, you can directly go to view it. Thank you.


Xcode plug-in development-jttmagicline I. Preparations

First go to kattrali/Xcode5-Plugin-Template to download the template file developed by xcode 5 plugins. It is best to clone git for future updates.

Copy the downloaded git repository ~ /Library/developer/xcode/templates/project templates/application plug-in/xcode5 plugin. xctemplate. If there is no corresponding sub-directory, create it manually. In addition, name the GIT repository xcode5 plugin. xctemplate.

Restart xcode 5 and create a new project. You can see the project of the xcode plugins type:

?

The original GitHub introduction page also contains three parts: usage, notes, and plugin debugging. To put it simply:

  • Usage: The Role of the template project. click File> do action in the xcode menu to bring up a hello World dialog box.
  • Notes:
    • In the xcode project of the plug-in, there is also an info. plist file. You can disable the plug-in function by setting xcpluginhasui to yes.
    • To support different xcode, such as xcode 5.0.2 and xcode 5.1.1, you need to set the dvtplugincompatibilityuuids option of the info. plist file and add the uuid of different xcode. How to view xcode UUID:

      Defaults read/applications/xcode. APP/contents/INFO dvtplugincompatibilityuuid

  • Plugin debugging: Because plugin cannot be used to view results in real time, you can use nslog (...) check whether the output is normal, and the log results are recorded in/var/log/system. log File, you can use the console program or tail command to view.

You can also refer to this article: xcode5 plugins development Introduction

?

2. xcode Plugin: vv1_enter

Vv1_enter is an xcode plug-in developed by @ onevcat meoshen. Its function is to automatically generate standard document comments after "//" is entered in xcode, which is indeed very useful and practical.

Because I have a very serious code cleanliness and want a clear module relationship between codes, therefore, we often get used to the whole line "////////////... "to separate the code modules to keep them beautiful. For example:

Simple # pragma mark-it has left me unsatisfied.

Inspired by vv1_enter, I am determined to write an input "MGL" and generate a whole line of code "////////////... "xcode plug-in -- jttmagicline. (This is a sentimental plug-in name)

The jttmagicline code and overall architecture refer to the vv1_enter code of meoshen. Therefore, the title of this section is directly assigned to vv1_enter.

?

Iii. How jttmagicline works

After reading the source code of vv1_enter for half a time, I understood the principle of vv1_enter and modeled it on jttmagicline.
Next, let's talk about the working principle of jttmagicline (which is roughly the same as that of vv1_enter ):

  • After the plug-in starts, it starts to listen to text changes in nstextview, that is, text changes in the editing area of xcode.
  • When the text in the xcode editing area is changed, the text in the row where the cursor is currently located is obtained and matched with the string that triggers the Replacement Event (for example, MGL ).
  • If the match is successful, create a new keyboard event class to simulate various Keyboard Events:
    • Command + Delete: delete this row
    • Command + V: paste the string to be replaced. Here is "///////////////..."
    • Return: Press ENTER + line feed to facilitate lazy developers, such as me
    • Restore Paste board content and various parameters

?

Iv. Code

It has been open-source to GitHub. The Code logic is still very clear because of the reference to the miaoshen code. If you are interested, let's take a look at download: guesn10000/jttmagicline.

Comments have been written in the code, which is easy to understand.

There is a todo. h In the project, obviously there are still many problems or the function is not perfect, such as the problem of setting the panel, command + Z, etc., I will continue to improve.

?

5. Build and use xcplugin

After compiling the code, you can build it in ~ The generated xcplugin file is displayed in the/library/Application Support/developer/shared/xcode/plug-ins directory:

If you think that it is too troublesome to jump to the directory every time or you cannot remember the path of the plug-in directory, you can get an alias directory like me. zshrc or. bash_profile (For details, refer to different shells ):

alias cdxcplugins=‘cd ~/Library/Application\ Support/Developer/Shared/Xcode/Plu$alias cdoxcplugins=‘cdxcplugins;open .‘

?

Okay, restart xcode.
In the text editing area of xcode, enter MGL, LA:

Success.

?

Vi. Deficiency

In fact, the last section can be called issue. This plug-in was used for a long time when I wrote this blog post, and many other functions were not complete. I remember todo. h:

# Ifndef jttmagicline_todo_h # define jttmagicline_todo_h/* 1. added the setting panel to set the replacement string, the string that triggers the Replacement Event, and disable the plug-in function. fix the problem that command + z cannot restore a line string. For more information, see vv1_enter 3. added support for xcode 6 */# endif

I will continue to improve it. For example, I will go back to the regular expression first, go to the source code of meoshen, and then come back to improve jttmagicline. Let's take a look, because this plug-in temporarily satisfies my needs.

?

Code for interest and try new things.



Xcode plug-in development-jttmagicline

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.