Code Monkey home page Code Monkey logo

hksnippet's Introduction

HKSnippet - Xcode plug-in

HKSnippet is a xcode plug-in for creating code snippet with triggers strings.

Demo

What Can it do ?

  • minimize input for often used code snippet.
  • Input code sinppet with paramters. ( NEW! )
  • define your own trigger & snippet.
  • export & import your customized snippet to and from config file.
  • support undo - redo operation.

Install

  • The recommanded way to install HKSnippet is to use Alcatraz. Install Alcatraz followed by the instruction, restart your Xcode. You can find HKSnippet in the list. Just click the install button.

  • another way is to clone this repo, Build the project and it's done!

  • or you can also download from this link and move the plugin to path
    ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/
    then restart Xcode

Usage

This plug-in is very easy to use. By typing the trigger string , you will get the corresponding snippet.

for example , you want to write a property with noatomic and strong, you can type @pns , and you will get

@property (noatomic, strong) <#type#> *<#name#>

The belowing part is pre-defined triggers and snippet :

  • Strong
@ps 	@property (strong) type *value; 

@prs	@property (strong, readonly) type *value;

@pns	@property (noatomic, strong) type *value;

@prns	@property (nonatomic, strong, readonly) type *value;


  • Weak
@pw 	@property (weak) type *value; 

@prw	@property (weak, readonly) type *value;

@pnw	@property (noatomic, weak) type *value;

@prnw	@property (nonatomic, weak, readonly) type *value;

  • Copy
@pc 	@property (copy) type *value; 

@prc	@property (copy, readonly) type *value;

@pnc	@property (noatomic, copy) type *value;

@prnc	@property (nonatomic, copy, readonly) type *value;

  • Assign
@pa 	@property (assign) type *value; 

@pra	@property (assign, readonly) type *value;

@pna	@property (noatomic, assign) type *value;

@prna	@property (nonatomic, assign, readonly) type *value;

  • @ff - General Getter
@ff 	

- (type *)name {
    if(!_name) {
        //Init Code
    }
    return _name;
}

  • @fv - UIView Getter
 @fv

- (UIView *)name {
    if(!_name) {
        _name = [UIView new];
        _name.backgroundColor = color;
    }
    return _name;
} 

  • @fl - UILabel Getter
@fl	

- (UILabel *)name {
    if(!_name) {
        _name = [UILabel new];
        _name.backgroundColor = [UIColor clearColor];
        _name.textAlignment = NSTextAlignmentCenter;
        _name.numberOfLines = 0;
        _name.textColor = color;
        _name.font = font;
        _name.text = text;
    }
    return _name;
}

  • @fi - UIImageView Getter
@fi

- (UIImageView *)name {
    if(!_name) {
        _name = [UIImageView new];
        _name.layer.cornerRadius = radius;
        _name.layer.masksToBounds = YES;
        _name.backgroundColor = [UIColor clearColor];
        _name.image = image;
    }
    return _name;
}

  • @fb - UIButton Getter
@fb

- (UIButton *)name {
    if(!_name) {
        _name = [UIButton new];
        _name.layer.cornerRadius = radius;
        _name.layer.masksToBounds = YES;
        _name.backgroundColor = [UIColor clearColor];
        [_name setTitleColor:title color forState:UIControlStateNormal];
        [_name setTitle: title  forState:UIControlStateNormal];
        [_name setImage:image forState:UIControlStateNormal];
    }
    return _name;
}

  • @ft - UITableView Getter
@ft

- (UITableView *)name {
    if(!_name) {
        _name = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _name.backgroundColor = [UIColor clearColor];
        _name.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _name.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _name.separatorColor = color;
        _name.delegate = table delegate;
        _name.dataSource = table datasource;

        [_name registerClass:[class name class] forCellReuseIdentifier:cellId];
    }
    return _name;
}

  • Declear
@cs		static NSString * const name = @\"value\";

@log	NSLog(@\"format\",data);

@ws		__weak typeof(self) weakSelf = self;

@ss		__strong typeof(weakSelf) strongSelf = weakSelf;

@mk		#pragma mark - section title

@pmk	#pragma mark - Private Method

@lmk	#pragma mark - LifeCycle

@gmk	#pragma mark - Getters & Setters

  • @lv - LoadView
@lv

- (void)loadView {
    [super loadView];
}

  • @ls - Layout Subviews
@ls

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat w = self.frame.size.width;
    CGFloat h = self.frame.size.height;
    //set subview frames
}

  • @vl - ViewWillLayoutSubviews
@vl

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    CGFloat w = self.frame.size.width;
    CGFloat h = self.frame.size.height;
    //set subview frames 
}

  • @init - Initialization
@init

- (instancetype)init {
    self = [super init];
    if (self) {
        //statements
    }
    return self;
}

  • @de - De-Init
@de

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

  • @tdd - UITableView Delegate & Datasource
@tdd

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return rows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellId];

    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return height;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

Advanced

You can even input a snippet with parameters, the format is as below:

<parameter1,parameter2...>@triger

for example , you want to declare a property getter for a label named "usernameLabel", and the font for the label is [UIFont systemFontOfSize:12.0f], you can type

usernameLabel,[UIFont systemFontOfSize:12.0f]@fl , and then the magic happens, you will got below code:

- (UILabel *)usernameLabel {
    if(!_usernameLabel) {
        _usernameLabel = [UILabel new];
        _usernameLabel.backgroundColor = [UIColor clearColor];
        _usernameLabel.textAlignment = NSTextAlignmentCenter;
        _usernameLabel.numberOfLines = 0;
        _usernameLabel.textColor = <#color#>;
        _usernameLabel.font = [UIFont systemFontOfSize:12.0f];
        _usernameLabel.text = <#text#>;
    }
    return _usernameLabel;
}

Setting

After the install of the plug-in ,you will find the menu in the top "Plugins -> HKSnippet", Click that menu, you can see the belowing pannel where you can define your own triggers or edit the existing triggers & snippets.

You can alse export your trigger & sniippet to a configuration file which can be use to share with others.

Setting1

You can search snippet with trigger Setting2

Edit the snippet Setting3

LICENCE

HKSnippet is available under the MIT license. See the LICENSE file for more info.

hksnippet's People

Contributors

hunk3000 avatar

Stargazers

 avatar 任健生 avatar Dinesh Raja avatar ffasMobile avatar Pearl Terry avatar Gustavo Verdun avatar  avatar  avatar Guangjun Chen avatar zgpeace avatar  avatar  avatar  avatar Curry avatar zhanghu avatar Ray Xiang avatar Sean Cheng avatar Shanti Rodríguez avatar Robert Thompson avatar James Rocco avatar Dylan Beadle avatar Bohdan Hernandez Navia avatar Parth Dabhi avatar  avatar RF avatar Dean Moore avatar Alessandro Aresta avatar Steve Kohls avatar Yanzhi Wang avatar Narcis avatar Grzegorz Owsiany avatar Andrey Tyushlyaev avatar Teena Nath Paul avatar Tomasz Rejdych avatar Pavel 'Pasha' Mazurin avatar Bernd Folberth avatar Hisma Mulya S avatar Xavier Nico avatar Hs_Yeah avatar  avatar iamdaiyuan avatar mayqiyue avatar anymuse avatar  avatar

Watchers

James Cloos avatar Hs_Yeah avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.