Skip to content

Instantly share code, notes, and snippets.

View bendjones's full-sized avatar

Ben D. Jones bendjones

View GitHub Profile
@parrots
parrots / CachingInterfaceController.h
Created April 14, 2015 02:32
CachingInterfaceController
@import WatchKit;
@interface CachingInterfaceController : WKInterfaceController
- (void)updateLabel:(WKInterfaceLabel *)label withString:(NSString *)string;
- (void)updateLabel:(WKInterfaceLabel *)label asHidden:(BOOL)hidden;
- (void)updateImage:(WKInterfaceImage *)image withImageNamed:(NSString *)imageName;
- (void)updateImage:(WKInterfaceImage *)image withBaseNameForAnimation:(NSString *)baseName withRange:(NSRange)range duration:(NSTimeInterval)duration repeatCount:(NSInteger)repeatCount;
- (NSString *)currentImageNameForImage:(WKInterfaceImage *)image;
@russbishop
russbishop / DictionaryAppend.swift
Last active November 15, 2016 16:00
Append to array inside a dictionary without copying
/// Appends a value to an array within a dictionary without triggering a copy.
/// Necessary in Swift 3 but expected to be obsoleted as the way inout works
/// will be changed (eliminating the need for the write-back copy)
func append<K, V>(value: V, toKey key: K, in dict: inout [K : Array<V>]) {
var a: [V]? = []
swap(&a, &dict[key])
a = a ?? []
a!.append(value)
swap(&a, &dict[key])