Skip to content

Instantly share code, notes, and snippets.

View TiernanKennedy's full-sized avatar

Tiernan Kennedy TiernanKennedy

View GitHub Profile
@TiernanKennedy
TiernanKennedy / Get avPlayer durations
Last active August 29, 2015 14:03
Get Duration of all items in AVPlayer
float count = 0.0;
for (AVPlayerItem *playerItem in self.player.items) {
CMTime duration = playerItem.asset.duration;
float durationSeconds = CMTimeGetSeconds(duration);
count = count + durationSeconds;
}
NSLog(@"total player duration: %.2f", count);
@TiernanKennedy
TiernanKennedy / Invite Array of friends to Facebook Dialog
Created August 16, 2013 00:39
Invite Array of friends to Facebook Dialog
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
if([invitations count] != 0){
NSString * stringOfFriends = [invitations componentsJoinedByString:@","];
[params setObject:stringOfFriends forKey:@"to"];
NSLog(@"%@", params);
}
@TiernanKennedy
TiernanKennedy / Get Device Name & OS Version
Last active December 20, 2015 23:39
Get Device Name & OS Version
-(NSDictionary *) getDeviceData {
NSString *OSVersion = [[UIDevice currentDevice] systemVersion];
NSString *deviceName = [self platformString];
return @{@"OSVersion":OSVersion, @"deviceName":deviceName};
}
- (NSString *) platform{
@TiernanKennedy
TiernanKennedy / Instantiation
Created March 26, 2013 18:39
New Obj C Syntax
// Updates to LLVM give us better instantiation methods
NSNumber *n1 = @1000; // [NSNumber numberWithInt:1000]
NSNumber *n2 = @3.1415926; // [NSNumber numberWithDouble:3.1415926]
NSNumber *c = @'c'; // [NSNumber numberWithChar:'c']
NSNumber *b = @YES; // [NSNumber numberWithBool:YES]
Arrays
// before
NSArray *words = [NSArray arrayWithObjects:@"list", @"of", @"words", nil];
@TiernanKennedy
TiernanKennedy / gist:5171953
Created March 15, 2013 18:28
A method with one argument (parameter) and a return type
// To create a method that accepts an integer (int) and returns that integer squared
- (void)viewDidLoad
{
[super viewDidLoad];
// first we delare our integer
int myInt = 666
// now look what's happening here - it will print "666 squared is 443556"
@TiernanKennedy
TiernanKennedy / Gesture Recognizer
Last active December 13, 2015 18:18
Adding a gesture recognizer
// first add a clear button that covers the screen
// Now add a gesture recognizer in ViewDidLoad
// with target "self" (this class)
// and selector (method) "hideCamera"
UISwipeGestureRecognizer* upSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(hideCamera)];
// set the direction of the swipe to up
[upSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
@TiernanKennedy
TiernanKennedy / fileOpenWebView
Created January 18, 2013 19:31
Opening a file in a UIWebView
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
[self loadDocument:@"iPhoneLibrary.key" inView:self.webView];