This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <objc/runtime.h> | |
@implementation UIViewController (Tracking) | |
+ (void)load { | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
Class class = [self class]; | |
SEL originalSelector = @selector(viewWillAppear:); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let listItem = list.removeAtIndex(fromIndex) | |
list.insert(listItem, atIndex: toIndex) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <objc/runtime.h> | |
@implementation UIViewController (Tracking) | |
+ (void)load { | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
Class class = [self class]; | |
SEL originalSelector = @selector(viewWillAppear:); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGSize maximumLabelSize = CGSizeMake(tableView.width, MAXFLOAT); | |
NSStringDrawingOptions options = NSStringDrawingTruncatesLastVisibleLine | | |
NSStringDrawingUsesLineFragmentOrigin; | |
NSDictionary *attr = @{NSFontAttributeName: [UIFont systemFontOfSize:15]}; | |
CGRect labelBounds = [string boundingRectWithSize:maximumLabelSize | |
options:options | |
attributes:attr | |
context:nil]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class func genRandStringLength(len: Int) -> String { | |
var randomString :String! = String(); | |
for index in 0..<len { | |
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
let randomIndex = arc4random_uniform(UInt32(countElements(letters))) | |
let index = Int(randomIndex) | |
let aChar = letters.characterAtIndex(index); | |
randomString = randomString.stringByAppendingString(aChar); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func localURL(filename: String) -> NSURL { | |
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) | |
let url = urls[urls.count-1] as NSURL | |
return url.URLByAppendingPathComponent(filename) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSInteger)binarySearch:(id)object inArray:(NSArray *)array { | |
NSInteger minIndex = 0; | |
NSInteger maxIndex = [array count] - 1; | |
while (maxIndex >= minIndex) { | |
NSInteger midIndex = (maxIndex + minIndex) / 2; | |
if ([array[midIndex] compare:object] == NSOrderedAscending) { | |
minIndex = midIndex + 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSArray *)mergeSort { | |
if ([self count] <= 1) { | |
return self; | |
} | |
NSArray *array1, *array2; | |
//If array count is odd | |
NSInteger arrayHalfSize = [self count] / 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSArray *)insertionSort { | |
//Do nothing if the array has less than or only 1 object | |
if ([self count] <= 1) { | |
return self; | |
} | |
NSMutableArray *sortedArray = [self mutableCopy]; | |
for (int j = 1; j < [sortedArray count]; j++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGRect rectFor1PxStroke(CGRect rect) { | |
return CGRectMake(rect.origin.x + 0.5, rect.origin.y + 0.5, rect.size.width - 1, rect.size.height - 1); | |
} |