Skip to content

Instantly share code, notes, and snippets.

@hacknicity
hacknicity / gist:274dde42f296f095a011b3d399a5ffc1
Created March 15, 2023 14:01
Swift code for finding first future date from an array
// We only want to calculate this once
let now = Date.now
// Create some test data
let allMatches: [Date] = (0...10)
.map { _ in
let randomNumberOfDays = (-1000...1000).randomElement()!
return Calendar.current.date(byAdding: .day, value: randomNumberOfDays, to: now)!
}
@hacknicity
hacknicity / .gitignore
Created January 31, 2023 11:44
.gitignore I use in my iOS/Mac apps (in each repository, not global)
*~
.DS_Store
####################################################################################################
#
# The following are taken from https://github.com/github/gitignore/blob/main/Global/macOS.gitignore on 28 Mar 2022 (2bb963b dated 6 Jul 2017)
#
# General
.DS_Store
@hacknicity
hacknicity / ContentView.swift
Created January 27, 2023 10:45
SwiftUI sample showing different system font widths, including an undocumented extra expanded width
//
// ContentView.swift
// SystemFontWidths
//
// Created by Geoff Hackworth on 27/01/2023.
//
import SwiftUI
struct ContentView: View {
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ADTSystemFontTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[ADTSystemFontTableViewCell reuseIdentifier] forIndexPath:indexPath];
UIFontDescriptor *fontDescriptor = [self fontDescriptorAtIndexPath:indexPath];
NSDictionary *widthSetting = @{UIFontWidthTrait : @(-1.0)};
fontDescriptor = [fontDescriptor fontDescriptorByAddingAttributes:@{UIFontDescriptorTraitsAttribute: widthSetting}];
cell.fontDescriptor = fontDescriptor;
@hacknicity
hacknicity / ECTStepAddViewController.m
Created October 10, 2021 17:10
UIPIckerView+SelectionBarLabelSupport
//
// ECTStepAddViewController.m
// EasyCookingTimer
//
// Created by Geoff Hackworth on 03/03/2012.
// Copyright (c) 2012 Hacknicity. All rights reserved.
//
#import "ECTStepAddViewController.h"
import Foundation
extension UserDefaults {
/// Returns an empty `UserDefaults` instance suitable for unit testing.
///
/// Based on https://www.swiftbysundell.com/posts/the-power-of-userdefaults-in-swift
///
/// - Parameters:
/// - functionName: name of the unit test function.
@hacknicity
hacknicity / RenamedSFSybols_13_14.csv
Last active September 23, 2020 06:20
SF Symbols renamed between iOS 13 and 14
iOS 13 name iOS 14 name
arrow.2.circlepath arrow.triangle.2.circlepath
arrow.2.circlepath.circle arrow.triangle.2.circlepath.circle
arrow.2.circlepath.circle.fill arrow.triangle.2.circlepath.circle.fill
arrow.branch arrow.triangle.branch
arrow.merge arrow.triangle.merge
arrow.right.arrow.left arrow.left.arrow.right
arrow.right.arrow.left.circle arrow.left.arrow.right.circle
arrow.right.arrow.left.circle.fill arrow.left.arrow.right.circle.fill
arrow.right.arrow.left.square arrow.left.arrow.right.square