A new Xcode “legal” plug-in has been made. The reason why it is legal is that Xcode 8 starts to disable all the previous third-party plug-ins. To pass the security check, the newly developed plug-in must use the official Xcode Editor Extension. The EasyCode plugin is based on Extension, which at the moment offers only a “meagre” API, but at least the Xcode team is taking a first step.

Making affixed first address: https://github.com/music4kid/EasyCode-Xcode.

rendering



To the chase

The existing API of Extension can only fetch the contents of the file currently being edited, nothing more. Fortunately, you can modify the contents of the current file. Back when I wrote FastStub, I had the idea that you could quickly insert a piece of code using an acronym.

The reason is that XCode’s current auto-completion function is not powerful enough. For example, when writing UIViewController, you often need to write the following code:

- (void)viewDidLoad {
    [super viewDidLoad];
}Copy the code

In Xcode 8, you must type -(void) before the completion prompt appears, which means that the return value of the function must match exactly, and the necessary [super viewDidLoad]; It won’t help you type it. I personally feel the need for a faster input method to enhance the experience.

Of course we can use the Snippet Library that comes with Xcode to generate a shortcut, but it is difficult for me to do this every time, and it is more difficult to create a shortcut for every common Code block. It is easier to write a plug-in and programmers know programmers better.

In simple terms, EasyCode follows the rule of taking the first letter of the corresponding function word to match (take the first three words, not enough to take two).

For example, viewDidLoad is decomposed into viewDidLoad, which corresponds to the abbreviation of VDL. In Xcode, the VDL can be replaced with the above code block simply by triggering the plug-in function through the menu or shortcut key.

Similarly, input vda to generate

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}Copy the code

Enter the DRM

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}Copy the code

Input the sio

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    <#code#>
}Copy the code

Input HTW

- (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event
{
    <#code#>
}Copy the code

Input the Dr

- (void)drawRect:(CGRect)rect
{
    <#code#>
}Copy the code

Several APIS in GCD are often encountered, and there will be conflicts after abbreviations, so some adjustments have been made

Enter DAFM (Dispatch after main Queue)

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        <#code to be executed after a specified delay#>
    });Copy the code

Enter DASM (Dispatch async main queue)

dispatch_async(dispatch_get_main_queue(), ^{
        <#code#>
    });Copy the code

Guess what DAFG, dAFM stands for?

There are also a few snippets of shortcut code that require some memorization:

Del corresponding

([UIApplication sharedApplication].delegate)Copy the code

V corresponding

- (void)<#method#>Copy the code

Corresponding to the p

@property (nonatomic, strong) <#type#>         <#name#>Copy the code

W corresponding

__weak __typeof(self) wself = self;Copy the code

N the corresponding

[NSNotificationCenter defaultCenter]Copy the code

U corresponding

[NSUserDefaults standardUserDefaults]Copy the code

Img corresponding

[UIImage imageNamed:<#(nonnull NSString *)#>];Copy the code

Bun corresponding

[[NSBundle mainBundle] pathForResource:<#(nullable NSString *)#> ofType:<#(nullable NSString *)#>];Copy the code

These are the parts of the code THAT I usually don’t want to tap, but they’re purely finger movements, and it’s a lot easier when they’re automatically generated.

The plugin can also quickly generate template code.

For example, typing BTN produces:

UIButton *btn = [UIButton new];
[btn setBackgroundColor:<#(UIColor * _Nullable)#>];
[btn setTitle:<#(nullable NSString *)#> forState:UIControlStateNormal];
[btn addTarget:<#(nullable id)#> action:<#(nonnull SEL)#> forControlEvents:UIControlEventTouchUpInside];
[<#self#> addSubview:btn];
<#self.btn#> = btn;Copy the code

Those of you who write UI Buttons often know how boring this code is if you type it one by one.

Lb: input

UILabel *lb = [UILabel new];
lb.text = <#text#>;
lb.textColor = <#(UIColor * _Nullable)#>;
lb.font = [UIFont systemFontOfSize:<#(CGFloat)#>];
lb.backgroundColor = [UIColor clearColor];
[<#self#> addSubview:lb];
<#self.lb#> = lb;Copy the code

So iv, I don’t have to tell you what’s going to happen.

There are some other similar abbreviations. At this stage, I have added some API or abbreviations that I think are more commonly used. If they don’t meet my memory habits, I can configure shortcuts by myself after fork the project.

The goal of this plug-in is to reduce the number of repetitive code typing, the initial use of the feeling is more pleasant, suitable for both diligent (remember the API) and lazy (too lazy to type the full API) students.

Later, if you open up GUI interaction, it should become more practical.

Installation method:

Download the code and run it through Xcode8. Before running, sign the Target with your developer certificate.

Later, if Xcode can open up more APIS, we will consider putting them on AppStore.

Usage:

Create shortcut keys for menu items in Xcode (I have CMD +.) :



Press the shortcut key after the abbreviation:

Any questions or common code need to be added, welcome to github issue.

We also expect the Xcode team to open up more APIS in the future. Currently, there is no way to migrate FastStub.

Welcome to our official account: