Skip to content

Instantly share code, notes, and snippets.

View zoejessica's full-sized avatar
🐗
skiing uphill

Zoë Smith zoejessica

🐗
skiing uphill
View GitHub Profile
@zoejessica
zoejessica / UIView + DebugObject
Created March 15, 2014 12:23
Ben Scheirman's category on UIView to get quick look debugging on UIView variables (not just properties)
// http://benscheirman.com/2014/03/quick-look-debugging-with-uiview/
#import "UIView+DebugObject.h"
@implementation UIView (DebugObject)
- (id)debugQuickLookObject {
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
@zoejessica
zoejessica / gist:770a59e6f380e575ae94
Last active August 29, 2015 14:01
Dynamic cell height calculation where prototype cells' heights will vary according to one important UI element
// In a subclass of UITableViewCell:
- (void)awakeFromNib {
// http://stackoverflow.com/a/14127936/2199136
[super awakeFromNib];
[self layoutIfNeeded];
self.originalSize = self.bounds.size;
self.originalimportantUIElementSize = self.originalimportantUIElement.bounds.size;
}
@zoejessica
zoejessica / gist:2df4bc074691b8cf2f14
Created May 13, 2014 13:36
Calculating cell heights from auto layout prototype cells, each type of which will always be the same height
// http://stackoverflow.com/a/16881312/2199136
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = [self cellIdentifierForIndexPath:indexPath];
static NSMutableDictionary *heightCache;
if (!heightCache)
heightCache = [[NSMutableDictionary alloc] init];
NSNumber *cachedHeight = heightCache[cellIdentifier];
if (cachedHeight)
return cachedHeight.floatValue;
@zoejessica
zoejessica / Badged pin
Created April 24, 2015 17:05
Badged pin (eg for maps) using IB_Designable and IBInspectable
#import <UIKit/UIKit.h>
IB_DESIGNABLE @interface BadgedPin : UIView
@property (nonatomic, assign) IBInspectable CGFloat badgeDiameter;
@property (nonatomic, strong) IBInspectable UIColor *badgeColor;
@property (nonatomic, assign) IBInspectable CGFloat badgeStrokeWidth;
@property (nonatomic, strong) IBInspectable UIColor *fillColor;
@property (nonatomic, strong) IBInspectable NSString *imageName;
@zoejessica
zoejessica / chunk.swift
Created May 16, 2016 21:42
Chunk an array into subarrays
extension Array {
func chunk<T : Equatable>(by valueToCompare: (Element) -> T) -> [[Element]] {
var currentValue = self[0]
var startIndex = 0
var splits = [[Element]]()
for (index, value) in self.enumerate() {
if valueToCompare(value) != valueToCompare(currentValue) {
let newSplit = self[startIndex..<index]
splits.append(Array(newSplit))
startIndex = index

Keybase proof

I hereby claim:

  • I am zoejessica on github.
  • I am zoejessica (https://keybase.io/zoejessica) on keybase.
  • I have a public key whose fingerprint is FB40 ACD5 4224 8770 4470 6C39 035A F65B 02C1 4E6B

To claim this, I am signing this object:

@zoejessica
zoejessica / multilinelabelnode.swift
Created April 29, 2017 09:56
Multiline SKLabelNode in Swift 3
// from https://oleb.net/blog/2016/08/swift-3-strings/
extension String {
func wrapped(after: Int) -> [String] {
var i = 0
let lines = self.characters.split(omittingEmptySubsequences: false) { character in
switch character {
case "\n",
" " where i >= after:
i = 0
@zoejessica
zoejessica / multilinelabelnode.swift
Created April 29, 2017 09:56
Multiline SKLabelNode in Swift 3
// from https://oleb.net/blog/2016/08/swift-3-strings/
extension String {
func wrapped(after: Int) -> [String] {
var i = 0
let lines = self.characters.split(omittingEmptySubsequences: false) { character in
switch character {
case "\n",
" " where i >= after:
i = 0
@zoejessica
zoejessica / Activity.swift
Created July 8, 2017 14:33 — forked from zwaldowski/Activity.swift
os_activity_t for Swift 3
//
// Activity.swift
//
// Created by Zachary Waldowski on 8/21/16.
// Copyright © 2016 Zachary Waldowski. Licensed under MIT.
//
import os.activity
private final class LegacyActivityContext {
import Foundation
import CoreData
import CloudKit
// https://github.com/macmade/user-defaults/blob/master/swift/Preferences.swift
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2017 Jean-David Gadina - www.xs-labs.com