Variable |
Type |
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
func poll() { | |
let backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) | |
let source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, backgroundQueue) | |
let interval: UInt64 = UInt64(10) * NSEC_PER_SEC | |
let leeway: UInt64 = UInt64(0.1) * NSEC_PER_SEC | |
dispatch_source_set_timer(source, DISPATCH_TIME_NOW, interval, leeway) | |
dispatch_source_set_event_handler(source) { () -> Void in | |
self.pollDidFinish(source: source) |
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
import UIKit | |
extension UIViewController { | |
func addChildVC(viewController: UIViewController) { | |
addChildViewController(viewController) | |
view.addSubview(viewController.view) | |
viewController.didMoveToParentViewController(self) | |
} | |
} |
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
var block : @objc_block (NSString!) -> Void = { | |
[unowned self] (string : NSString!) -> Void in | |
let jsText = "\(string)\n" | |
self.outputTextView.setText(jsText, concatenate: true) | |
} | |
context.setObject(unsafeBitCast(block, AnyObject.self), | |
forKeyedSubscript: "print") |
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 dataTask = urlSession.dataTaskWithURL(url!, completionHandler: { [unowned self] (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in | |
//add code here | |
}) |
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
NSString *html = @"<bold>Wow!</bold> Now <em>iOS</em> can create <h3>NSAttributedString</h3> from HTMLs!"; | |
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; | |
NSAttributedString *attrString = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:nil]; |
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
//Add to Project-Prefix.pch | |
#ifdef DEBUG | |
#define debugLog(...) NSLog(__VA_ARGS__) | |
#else | |
#define debugLog(...) // Nothing | |
#endif |
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
//In UIViewController subclass | |
@interface UIWindow (AutoLayoutDebug) | |
+ (UIWindow *)keyWindow; | |
- (NSString *)_autolayoutTrace; | |
@end | |
- (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation | |
{ | |
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; |
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
//From https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html | |
- (NSDate *)dateFromRFC3339String:(NSString *)dateString { | |
static NSDateFormatter *sRFC3339DateFormatter = nil; | |
if (sRFC3339DateFormatter == nil) { | |
sRFC3339DateFormatter = [[NSDateFormatter alloc] init]; | |
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; | |
[sRFC3339DateFormatter setLocale:enUSPOSIXLocale]; |
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
UIView *autoLayoutView = [[UIView alloc] init]; | |
autoLayoutView.backgroundColor = [UIColor redColor]; | |
autoLayoutView.translatesAutoresizingMaskIntoConstraints = NO; | |
[self.view addSubview:autoLayoutView]; | |
NSDictionary *views = NSDictionaryOfVariableBindings(autoLayoutView); | |
NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[autoLayoutView]|" | |
options:nil | |
metrics:nil |