Skip to content

Instantly share code, notes, and snippets.

@leilee
leilee / change_extension.sh
Created June 19, 2017 09:11
batch change file extension
for old in *.m; do mv $old `basename $old .m`.mm; done

AAAA.h

#import <Foundation/Foundation.h>

@interface AAAA : NSObject

@property NSMutableArray* dogs;
@leilee
leilee / runScript.sh
Created June 14, 2017 12:04
Marking TODO's, FIXME's With A Legit Xcode Warning
TAGS="TODO:|FIXME:"
find "${SRCROOT}" -not -path "${SRCROOT}/Pods/*" \( -name "*.h" -or -name "*.m" -or -name "*.swift" -type f \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 300, 200)];
view.backgroundColor = [UIColor blueColor];
[self.view addSubview:view];
[view addObserver:self forKeyPath:@"frame" options:0 context:NULL];
@leilee
leilee / UIColor (Random).m
Last active June 6, 2017 07:01
generate random UIColor
@interface UIColor (Random)
+ (instancetype)randomColor;
@end
@implementation UIColor (Random)
+ (instancetype)randomColor
{
@leilee
leilee / coordinate_systems.swift
Created May 27, 2017 06:01 — forked from phi161/coordinate_systems.swift
Converting Between View Coordinate Systems
import UIKit
import PlaygroundSupport
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Main view
self.view.backgroundColor = .black
@leilee
leilee / ios-cell-registration-swift.md
Created April 4, 2017 04:13 — forked from gonzalezreal/ios-cell-registration-swift.md
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@leilee
leilee / regexDemo.swift
Last active November 14, 2017 21:41
Swift regex matches
//: Playground - noun: a place where people can play
import Foundation
extension String {
func matchs(for regex: String) -> [String] {
let regex = try! NSRegularExpression(pattern: regex, options: [])
let matchs = regex.matches(in: self, options: [], range: NSRange(location: 0, length: characters.count))
return matchs.map { (self as NSString).substring(with: $0.range) }
}
@leilee
leilee / HairlineConstraint.swift
Created January 12, 2017 05:20
create 1px height line
class HairlineConstraint: NSLayoutConstraint {
override func awakeFromNib() {
super.awakeFromNib()
constant = 1.0 / UIScreen.mainScreen().scale
}
}
public struct Queues {
static var GlobalMainQueue: dispatch_queue_t {
return dispatch_get_main_queue()
}
static var GlobalUserInteractiveQueue: dispatch_queue_t {
return dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)
}
static var GlobalUserInitiatedQueue: dispatch_queue_t {