Skip to content

Instantly share code, notes, and snippets.

View patzearfoss's full-sized avatar

Pat Zearfoss patzearfoss

View GitHub Profile
//: Playground - noun: a place where people can play
import UIKit
extension Array where Element: FloatingPoint {
/// Returns the sum of all elements in the array
var total: Element {
return reduce(0, +)
}
/// Returns the average of all elements in the array
[{"value":"Exported from Microsoft Outlook (Do not delete)\n[outlook:3:1131] \n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131]\n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131] \n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131] \n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131]\n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131]\n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131] \n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131] \n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131]\n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131] \n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131] \n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131]\n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131]\n\nExported from Microsoft Outlook (Do not delete)\n[outlook:3:1131]\n\nExported from Microsoft Outlook (Do not
class ThingManager {
var things: [String: Thing] = [:]
func addThing(_ thing: Thing) {
self.things[thing.address] = thing
}
func removeThingWith(address: String) {
self.things.removeValue(forKey: address)
Message: 11
Date: Fri, 1 Jan 2016 14:21:35 -0800
From: Ethan Diamond <[email protected]>
To: Chris Lattner <[email protected]>
Cc: [email protected]
Subject: Re: [swift-evolution] Closure Syntax
Message-ID:
<CA+TuH2kozmhFMVKWrjMarc0C9B_Z2mCB=D+GZ10=BC=Kj1fFLA@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
@patzearfoss
patzearfoss / function_weirdness.swift
Created September 6, 2015 04:36
Shows some funky(func-y) stuff in swift
//: Playground - noun: a place where people can play
import UIKit
var f_var: () -> String = {
return "Wat"
}
let f1: () -> String = {
return "Indubitably"
+- (void)willSave
+{
+ static const unichar kUnicharMax = USHRT_MAX;
+ NSString *heavyString = [NSString stringWithCharacters:&kUnicharMax length:1];
+
+ self.firstNameSortValue = [self.firstName length] ? self.firstName : heavyString;
+ self.lastNameSortValue = [self.lastName length] ? self.lastName : heavyString;
+ self.companySortValue = [self.company length] ? self.company : heavyString;
+}
- (void)typeButtonTap:(id)sender
{
UITableViewCell *cell = (UITableViewCell *)sender;
NSIndexPath *path = [self.tableView indexPathForCell:cell];
ESCContactEditViewModelBase *viewModel = [self viewModelForIndexPath:path];
[self displayTypeSelectorForViewModel:viewModel];
}
#import "CBKClassToChange.h"
@implementation CBKClassToChange
+ (void)load
{
[NSKeyedUnarchiver setClass:self forClassName:@"CBClassToChange"];
}
- (void)encodeWithCoder:(NSCoder *)aCoder
/// .h
@interface mySingleton : NSObject
@property (nonatomic, strong) id someData;
+ (id)sharedInstance;
+ (void)probablySuperfluousStartup;
+ (void)probablyUnnecessaryShutdown;
@end
/// .m
static mySingleton *sharedInstance;
- (void)setDelegate:(id<UINavigationControllerDelegate>)delegate
{
[NSException raise:@"Wrong delegate error" format:@"You're actually using this? 99% sure you meant mailComposerDelegate"];
}