Skip to content

Instantly share code, notes, and snippets.

View danielctull's full-sized avatar

Daniel Tull danielctull

View GitHub Profile
public extension NSIndexPath {
// Allows us to split NSIndexPaths
public subscript (subrange: Range<Int>) -> NSIndexPath? {
guard subrange.startIndex >= 0 else {
return nil
}
@danielctull
danielctull / Example.swift
Last active August 29, 2015 14:24
Use generics to get a child view controller of a given type
if let tabViewController = self.contentViewController?.childViewControllerWithType(NSTabViewController) {
// tabViewController is an NSTabViewController, woop!
}
@danielctull
danielctull / gist:3f60aeff0bd3de1bca46
Created June 7, 2015 09:53
Arranging to meet up on Twitter.
a: “We’re in X!”
b: “Where is everyone?”
c: “Hey we’re in Y!”
d: “Hey we’re in Z!! Come join us!”
c: “@a Oh, we tweeted at the same time, want to come to Y or we can head to X?”
a: “@c We’ll head to you guys”
b: “@a A few of us will head to you at X”
import HealthKit
public extension HKWorkout {
public func predicateForSamplesDuringActivePeriods() -> NSPredicate {
let subpredicates = activePeriods.map { start, end -> NSPredicate in
HKQuery.predicateForSamplesWithStartDate(start, endDate: end, options: .StrictStartDate | .StrictEndDate)
cd "$PROJECT_DIR"
infoPlist="${SRCROOT}/${INFOPLIST_FILE}"
infoPath="${infoPlist%.*}"
infoName=$(basename "${infoPath}")
infoHeader="${infoPath}.h"
infoImplementation="${infoPath}.m"
infoHeaderImport=$(basename "${infoHeader}")
rm -f "$infoHeader"
@import Foundation;
typedef void(^DCTAuthPlatformCompletion)(BOOL success);
typedef void(^DCTAuthPlatformURLOpener)(NSURL *URL, DCTAuthPlatformCompletion completion);
typedef void(^DCTAuthPlatformExpirationHandler)();
typedef id(^DCTAuthPlatformBeginBackgroundTaskBlock)(DCTAuthPlatformExpirationHandler expirationHandler);
typedef void(^DCTAuthPlatformEndBackgroundTaskBlock)(id identifier);
@interface DCTAuthPlatform : NSObject
@danielctull
danielctull / gist:88651165fdc9a7130ed9
Last active August 29, 2015 14:11
Apple's example for the rest of us…
if (error) {
// In your app, handle this error really beautifully.
NSLog(@"An error occured in %@: %@", NSStringFromSelector(_cmd), error);
abort();
}
// In your app, handle this error in an awe-inspiring way.
// In your app, masterfully handle this error.
// In your app, handle this error like a pro.
// In your app, handle this error gracefully.
@import UIKit;
@interface ASRKeyboardNotificationValues : NSObject
- (instancetype)initWithNotification:(NSNotification *)notification;
@property (nonatomic, readonly) NSNotification *notification;
@property (nonatomic, readonly) NSTimeInterval animationDuration;
@property (nonatomic, readonly) UIViewAnimationCurve animationCurve;
@property (nonatomic, readonly) UIViewAnimationOptions animationOptions;
CGRect PSPDFRectSafeInset(CGRect rect, CGFloat dx, CGFloat dy) {
CGRect insetRect = CGRectInset(rect, dx, dy);
if (CGRectIsNull(insetRect)) {
insetRect = CGRectMake(CGRectGetMidX(rect), CGRectGetMidY(rect), 0.f, 0.f);
}
return insetRect;
}
@danielctull
danielctull / gist:44b5809b4ae7a4826661
Last active August 29, 2015 14:06
HKSampleQuery returns an array of AnyObject as a result. Now, I'm almost guaranteed that it will be an array of HKQuantitySample objects. I would like to end up with a list of NSDate objects for dates I already have Health sample data for that. I figure I can filter the results array to only include HKQuantitySample objects and then map them to …
import HealthKit
let quantityType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass)
let query = HKSampleQuery(sampleType:quantityType, predicate:nil, limit:0, sortDescriptors:nil) {
query, results, error in
// results is [AnyObject]
let samples = results.filter {
($0 as? HKQuantitySample) != nil