This file contains 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
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath | |
{ | |
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; | |
for (id obj in cell.subviews) { | |
if ([NSStringFromClass([obj class]) isEqualToString:@"UITableViewCellScrollView"]) { | |
UIScrollView* scroll = (UIScrollView*)obj; | |
scroll.delaysContentTouches = NO; | |
break; | |
} |
This file contains 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
- (void)registerForAppStateNotifications | |
{ | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; | |
} | |
- (void)applicationDidEnterBackground | |
{ | |
self.suspendedRotation = [self.imageView.layer.presentationLayer valueForKeyPath:@"transform.rotation.z"]; | |
} |
This file contains 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
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { | |
// if decelerating, let scrollViewDidEndDecelerating: handle it | |
if (decelerate == NO) | |
[self snapTable]; | |
} | |
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { | |
[self snapTable]; | |
} |
This file contains 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
@implementation NSColor (DDExtensions) | |
- (float)distanceTo:(NSColor*)color | |
{ | |
// Calculate color similarity/distance in RGBA color space | |
// http://stackoverflow.com/questions/4754506/color-similarity-distance-in-rgba-color-space | |
// max((r₁-r₂)², (r₁-r₂ - a₁+a₂)²) + | |
// max((g₁-g₂)², (g₁-g₂ - a₁+a₂)²) + | |
// max((b₁-b₂)², (b₁-b₂ - a₁+a₂)²) |
This file contains 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)deviceSize | |
{ | |
CGSize size = [UIScreen mainScreen].bounds.size; | |
if ([UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] > 1) { | |
size = CGSizeMake(size.width * 2, size.height * 2); // Retina screenshot size support | |
} | |
return size; | |
} |
This file contains 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
// | |
// AFNetworkingGDataXMLHTMLResponseSerializer.m | |
// | |
// Created by _ on 17/07/14. | |
// Copyright (c) 2014 cobysy. All rights reserved. | |
// | |
#import "AFNetworkingGDataXMLHTMLResponseSerializer.h" | |
#import <GDataXML-HTML/GDataXMLNode.h> |
This file contains 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
// memoized Levenshtein Distance | |
// description given here: http://programmingpraxis.com/2014/09/12/levenshtein-distance/ | |
import Foundation | |
// memoize for a two parameter recursive function | |
func memoize<T1: Hashable, T2: Hashable, U>(body: ((T1, T2) -> U, T1, T2) -> U) -> ((T1, T2) -> U) { | |
var memo = [T1: [T2: U]]() | |
var result: ((T1, T2) -> U)! | |
result = { |
This file contains 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
How to patch a library imported with Cocoapods | |
Forking the library, applying your patch, and pointing to your fork in the Podfile would be your best option. | |
If the library contains the podspec: | |
``` | |
pod '<library>', :git => 'https://github.com/yourname/<library>.git' | |
``` | |
If the library does not contain the podspec, you have to copy the podspec to a local path and adjust it: |
This file contains 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 fontFamilyNames = UIFont.familyNames() | |
for familyName in fontFamilyNames { | |
println("------------------------------") | |
println("Font Family Name = [\(familyName)]") | |
let names = UIFont.fontNamesForFamilyName(familyName as! String) | |
println("Font Names = [\(names)]") | |
} |
This file contains 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
// Copyright (c) 2015 bysy.io. All rights reserved. | |
func recursiveFlatMap<TResult>(#root: AnyObject, | |
@noescape children: (AnyObject) -> [AnyObject]) -> [TResult] | |
{ | |
var result = [TResult]() | |
if let value = root as? TResult { | |
result.append(value) | |
} | |
result += children(root).flatMap( { recursiveFlatMap(root: $0, children: children) as [TResult] } ) |
OlderNewer