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
// View controller is a subclass of GLKViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
self.eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; | |
self.ciContext = [CIContext | |
contextWithEAGLContext:self.eaglContext |
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
+ (void) logCharacterSet:(NSCharacterSet*)characterSet | |
{ | |
unichar unicharBuffer[20]; | |
int index = 0; | |
for (unichar uc = 0; uc < (0xFFFF); uc ++) | |
{ | |
if ([characterSet characterIsMember:uc]) | |
{ | |
unicharBuffer[index] = uc; |
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
- (void)testAsyncExample | |
{ | |
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | |
__block BOOL hasRunBlock = NO; | |
[MyClass asyncCallback:^{ | |
hasRunBlock = YES; | |
dispatch_semaphore_signal(semaphore); | |
}]; |
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
CFAbsoluteTime startTimeStamp = CFAbsoluteTimeGetCurrent(); | |
<#code to time#> | |
static NSTimeInterval smoothedTimeTaken = 0.0; | |
NSTimeInterval timeTaken = (CFAbsoluteTimeGetCurrent() - startTimeStamp); | |
if (smoothedTimeTaken == 0) smoothedTimeTaken = timeTaken; | |
else smoothedTimeTaken = smoothedTimeTaken * 0.9 + timeTaken * 0.1; | |
NSLog(@"Took %0.1f ms (smoothed) to <#name of task#>", smoothedTimeTaken * 1000); |
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
static BOOL isRunningTests(void) __attribute__((const)); | |
- (BOOL)application:(UIApplication *)application | |
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
if (isRunningTests()) { | |
return YES; | |
} | |
// |
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
+ (NSString *)htmlFromBodyString:(NSString *)htmlBodyString | |
textFont:(UIFont *)font | |
textColor:(UIColor *)textColor | |
{ | |
int numComponents = CGColorGetNumberOfComponents([textColor CGColor]); | |
NSAssert(numComponents == 4 || numComponents == 2, @"Unsupported color format"); | |
// E.g. FF00A5 | |
NSString *colorHexString = 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
// For NSString to NSDate to parse server dates in the full ISO 8601 format | |
// E.g. 2014-02-11T10:22:46+00:00 | |
+ (NSDateFormatter *) iso8601FullDateFromatter | |
{ | |
static NSDateFormatter * dateFormatter; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
dateFormatter = [[NSDateFormatter alloc] init]; |
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
NSURL *url = [NSURL URLWithString:@"https://google.co.uk"]; | |
NSURLRequest *request = [NSURLRequest requestWithURL:url]; | |
NSError *error; | |
[NSURLConnection sendSynchronousRequest:request | |
returningResponse:nil | |
error:&error]; | |
NSLog(@"NSURLConnection error: %@", error.localizedDescription); | |
[[[NSURLSession sharedSession] |
OlderNewer