Skip to content

Instantly share code, notes, and snippets.

View hechen's full-sized avatar
🎯
Focusing

CHEN hechen

🎯
Focusing
View GitHub Profile
@hechen
hechen / UIColor+RandomColor.h
Last active August 29, 2015 14:18
Generate random Color using category based UIColor
//
// UIColor+RandomColor.h
// ViewImage
//
// Created by hechen on 15/4/8.
// Copyright (c) 2015年 hechen. All rights reserved.
//
#import <UIKit/UIKit.h>
//
// UIView+Image.h
// ViewImage
//
// Created by hechen on 15/4/8.
// Copyright (c) 2015年 hechen. All rights reserved.
//
#import <UIKit/UIKit.h>
@hechen
hechen / viewinit.m
Last active September 25, 2017 06:25
--- title: "Initializes View" summary: "Initializes a view inside a code block" completion-scope: Function or Method ---
<# view #> = ({
UIView *v = [[UIView alloc] init];
<# ... #>
v;
});
@hechen
hechen / tvds.m
Created August 15, 2017 02:50
--- title: "UITableViewDataSource" summary: "Placeholders for required UITableViewDataSource delegate methods" platform: iOS completion-scope: Class Implementation ---
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return <#number#>;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return <#number#>;
}
@hechen
hechen / tvdel.m
Created August 15, 2017 02:50
--- title: "UITableViewDelegate" summary: "Placeholders for required UITableViewDelegate protocol methods" platform: iOS completion-scope: Class Implementation ---
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
<#statements#>
}
@hechen
hechen / nscoding.m
Created August 15, 2017 02:50
--- title: "NSCoding Protocol Methods" summary: "Placeholders for NSCoding protocol methods" completion-scope: Class Implementation ---
#pragma mark - NSCoding
- (instancetype)initWithCoder:(NSCoder *)decoder {
self = [super init];
if (!self) {
return nil;
}
<# implementation #>
@hechen
hechen / lifecycle.m
Created August 15, 2017 02:51
--- title: "UIViewController Lifecycle" summary: "Placeholders for all of the view controller lifecycle methods" platform: iOS completion-scope: Class Implementation ---
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
@hechen
hechen / singleton.m
Created August 15, 2017 02:51
--- title: "Shared Singleton" summary: "Class method that returns a singleton instance" completion-scope: Class Implementation ---
+ (instancetype)shared<#name#> {
static <#class#> *_shared<#name#> = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_shared<#name#> = <#initializer#>;
});
return _shared<#name#>;
}
@hechen
hechen / swifttvds.swift
Created August 16, 2017 02:12
UITableViewDataSource Swift Version
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return <#count#>
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return <#count#>
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
<#code#>
@hechen
hechen / swiftassociatedobject.swift
Created August 16, 2017 02:13
AssociatedObject of swift version
private struct AssociatedKeys {
static var <#name#> = "<#name#>"
}
var <#name#>: String? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.<#name#>) as? String
}
set {