Skip to content

Instantly share code, notes, and snippets.

Avatar

David Beck davbeck

View GitHub Profile
@davbeck
davbeck / AssociatedProperty.swift
Created Feb 10, 2020
Swift friendly wrapper around associated objects.
View AssociatedProperty.swift
import ObjectiveC
extension objc_AssociationPolicy {
public static let retain = objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN
public static let retainNonatomic = objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC
public static let copy = objc_AssociationPolicy.OBJC_ASSOCIATION_COPY
public static let copyNonatomic = objc_AssociationPolicy.OBJC_ASSOCIATION_COPY_NONATOMIC
public static let assign = objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN
}
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active Dec 22, 2020
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
View InteractiveTransitionCollectionViewDeselection.m
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@lattner
lattner / async_swift_proposal.md
Last active Jan 21, 2021 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift
View async_swift_proposal.md

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

View workflow.md

Workflow

We use Jira to track bugs and features and git flow to track changes to the code. The workflow for a ticket goes as follows:

  1. The developer moves a ticket into the "In Progress" column, assigning it to themselves.

  2. The developer creates a new branch off of develop (or another feature branch if necessary) naming it feature/REALM-XXXXX-description where "REALM-XXXXX" is the ticket number in Jira and "description" is a 1-3 word description of the ticket.

  3. Any changes needed to fulfill the ticket are performed in 1 or more commits. Each commit should start with the ticket number, as in REALM-XXXXX Added link to make a gift. Prefixing the ticket number here causes the commit to appear in Jira.

@davbeck
davbeck / assets.rb
Last active Sep 26, 2020
Automatic Enum-based Xcassets in Swift
View assets.rb
#!/usr/bin/env ruby
require "active_support"
def assetCatalogsAtPath(path)
results = []
contents = Dir.entries(path)
@davbeck
davbeck / WKUIDelegate.m
Last active Feb 5, 2020
Boilerplate implementation of WKUIDelegate to support Javascript alerts.
View WKUIDelegate.m
#pragma mark - WKUIDelegate
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)())completionHandler
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
completionHandler();
@ketzusaka
ketzusaka / gist:12743fa9d6569dbb447d
Created Jun 6, 2014
Swift Operator Overloading Adding << On Array
View gist:12743fa9d6569dbb447d
/*
In Swift, you can overload operators. A common operator in Ruby for working with arrays is <<,
which is syntatic sugar for array.push(). Since Array's in Swift don't take bitwise operations, this is
an example demonstrating adding that operator to an array that contains any type.
As an extra tidbit, I've added >> to prepend an array with an object
*/
@infix func << <T>(inout array: Array<T>, item: T) {
array.append(item)
@davbeck
davbeck / README.md
Last active Aug 29, 2015
TNKPropertyKey
View README.md

It's become common practice to use an @selector for associated objects. This is useful because not only are SELs guaranteed to have a unique address, but because as of Xcode 5, Xcode will warn you when you use a selector that it does not know about. Meaning that it is somewhat protected against spelling mistakes.

This can also be useful when using string keys. For things like state restoration, where you want a key for a given property, you can use the selector for the getter, and get a string from that. Xcode will autocomplete the name for you, and will warn you if you misspell it.

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
    [super encodeRestorableStateWithCoder:coder];
    
    [coder encodeObject:self.feedID forKey:TNKPropertyKey(feedID)];
@uluckas
uluckas / gist:3129990
Created Jul 17, 2012
mergeChangesFromContextDidSaveNotification with core data bug workarounds
View gist:3129990
// See http://lists.apple.com/archives/cocoa-dev/2008/Jun/msg00237.html for bugs below
- (void)mergeChangesFromContextDidSaveNotification:(NSNotification*)notification {
NSManagedObject *object;
NSSet* updates;
// Workaround bug 5982319
// Fault in all updated objects because chnages to faults won't trigger fetchedResultsControlle
updates = [notification.userInfo objectForKey:NSUpdatedObjectsKey];
for (object in updates) {
[[self.roManagedObjectContext objectWithID:[object objectID]] willAccessValueForKey:nil];