Skip to content

Instantly share code, notes, and snippets.

View danielctull's full-sized avatar

Daniel Tull danielctull

View GitHub Profile
@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
enum MyEnum {
case StateA
case StateB
}
let enumValueA = MyEnum.StateA
let enumValueB = MyEnum.StateB
if enumValueA == enumValueB {
@danielctull
danielctull / gist:70a69e09d7b108cc2589
Created June 8, 2014 20:16
Error return in Switch using enumeration and associated error value
import Cocoa
enum Result {
case Success
case Failure(NSError)
}
func DoTask() -> Result {
return .Failure(NSError.errorWithDomain("Domain", code: 4, userInfo:nil))
}
- (BOOL)tableViewDataSource:(DCTTableViewDataSource *)tableViewDataSource shouldReloadRowAtIndexPath:(NSIndexPath *)indexPath {
ISUIssue *issue = [tableViewDataSource objectAtIndexPath:indexPath];
NSArray *keys = [issue.changedValuesForCurrentEvent allKeys];
if ([issue.changedValuesForCurrentEvent objectForKey:ISUIssueAttributes.issueID]) return YES;
if ([keys containsObject:ISUIssueAttributes.issueID]) return YES;
if ([keys containsObject:ISUIssueAttributes.title]) return YES;
@danielctull
danielctull / gist:9493221
Created March 11, 2014 19:28
Build phase, run script to check if appledoc is installed and run it if so
appledoc=`which appledoc`
if [ $appledoc ]; then
company="Daniel Tull";
companyID="uk.co.danieltull";
companyURL="http://danieltull.co.uk";
outputPath="/tmp/${PRODUCT_NAME}";
$appledoc \
@danielctull
danielctull / gist:8842328
Created February 6, 2014 11:17
Inset scrollviews
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self modifyEdgeInsetsOfScrollView:self.tableView];
[self modifyEdgeInsetsOfScrollView:self.webView.scrollView];
}
- (void)modifyEdgeInsetsOfScrollView:(UIScrollView *)scrollview {
scrollview.contentInset = [self modifiedEdgeInsets:scrollview.contentInset];
scrollview.scrollIndicatorInsets = [self modifiedEdgeInsets:scrollview.scrollIndicatorInsets];
}
- (void)checkConnectionWithError:(NSError *)error {
CWDURLSessionManagerState state = CWDURLSessionManagerStateConnected;
NSNumber *errorCode = @(error.code);
if ([[self noInternetErrorCodes] containsObject:errorCode])
state = CWDURLSessionManagerStateNotConnected;
if (self.state == state) return;
@danielctull
danielctull / gist:7170326
Created October 26, 2013 14:56
My tag + upload post Archive Scheme Script
echo "Starting Tag and upload to TestFlight with configuration: ${CONFIGURATION}"
if [[ ${CONFIGURATION} != "Release" ]]; then
exit
fi
cd ${SRCROOT}
PREVIOUSTAG=`git tag | grep "$s." | sort -r | head -1`
TAG="s.`git log --oneline | wc -l | tr -d ' '`"
echo "Starting Tag and upload to TestFlight with configuration: ${CONFIGURATION}"
if [[ ${CONFIGURATION} != "Release" ]]; then
exit
fi
cd ${SRCROOT}
PREVIOUSTAG=`git tag | grep "$s." | sort -r | head -1`
TAG="s.`git log --oneline | wc -l | tr -d ' '`"
fetchRequest.entity = [RNPFeedListEntry entityInManagedObjectContext:self.managedObjectContext];
// this is the main predicate to get the feed entries that belong to the us
NSPredicate *ownerPredicate = [NSPredicate predicateWithFormat:@"%K == %@ AND %K.%K == %@",
RNPFeedListEntryRelationships.owner, self, RNPFeedListEntryRelationships.feed,
RNPFeedAttributes.action, @(FeedAction_LIKE), self];
// this is the predicate to check that we have the required item
NSPredicate *itemPopulatedPredicate = [NSPredicate predicateWithFormat:@"(%K.%K == nil) OR (%K.%K != nil)",
RNPFeedListEntryRelationships.feed, RNPFeedAttributes.itemId,
RNPFeedListEntryRelationships.feed, RNPFeedRelationships.item];
fetchRequest.predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[ownerPredicate, itemPopulatedPredicate]];