Skip to content

Instantly share code, notes, and snippets.

View KevinVitale's full-sized avatar
👾
Game Boy

Kevin Vitale KevinVitale

👾
Game Boy
View GitHub Profile
@KevinVitale
KevinVitale / MyFrameworkBundle.swift
Last active September 10, 2017 16:35
Extensions for getting bundles
extension Bundle {
private final class _Internal { }
public static let framework = Bundle(for: _Internal.self)
}

``` func tuple(text: String, property: MutableProperty) -> (String, MutableProperty) { return (text, property) } let sp = street.producer.map { (text: String) in return tuple(text, property: self.street) } var producers = [SignalProducer<(String, MutableProperty), NoError>]([]) producers.append(sp) ```
@KevinVitale
KevinVitale / Matrix.swift
Last active August 29, 2015 14:23
Matrix as Protocol
import Foundation
public protocol MatrixProtocol {
var rows: Int {get }
var cols: Int { get }
typealias ElementType
var grid: [ElementType] { get set }
init(rows: Int, cols: Int)

Keybase proof

I hereby claim:

  • I am kevinvitale on github.
  • I am kevinvitale (https://keybase.io/kevinvitale) on keybase.
  • I have a public key whose fingerprint is 1A36 B552 08B0 3C27 2F38 2446 CBE2 DA64 86BA 62F8

To claim this, I am signing this object:

@KevinVitale
KevinVitale / nsnumber+json.m
Created April 3, 2015 03:31
NSNumber & floating-point JSON serializing
//------------------------------------------------------------------------------
// Source
id json = [@"Decimal" jsonFixture];
NSArray *coord = json[@"coord"];
NSLog(@"%@", coord);
//------------------------------------------------------------------------------
// Output
2015-04-02 23:28:58.629 xctest[56318:2467238] (
"16528.3",
"9940.17",
@KevinVitale
KevinVitale / will+RAC.swift
Last active August 29, 2015 14:14
Using 'RACObserve' to bind property values upon creation
// --- A note on all these 'willSet' stuff ---
//
// Upon initial creation:
// ◇ add as a child view controller (optional);
// ◇ add the child view controller's view to our own (optional);
// ◇ bind the frame to our own view's frame.size (required);
// - kvitale, 01/28/15
// empty state
var emptyStateController: EmptyStateController! {
@KevinVitale
KevinVitale / gist:8decddb5e20754907ded
Last active August 29, 2015 14:10
Filtering an array potentially containing optionals to all non-optionals
func toInfusionSlots(infusionSlots: [JSON]?) -> [InfusionSlot]? {
if let infusionSlots = infusionSlots {
let map = {
(infusionSlot: JSON) -> InfusionSlot?
in
return InfusionSlot(infusionSlot); // failable — init?()
}
let filter = {
(infusionSlot: InfusionSlot?) -> Bool
in
@KevinVitale
KevinVitale / InlineCallback
Created June 3, 2014 03:00
Swift-Bastardization#01
self.window!.rootViewController = {
() -> UINavigationController in
var viewController = UIViewController()
var navController = UINavigationController(rootViewController: viewController)
return navController
}()
import UIKit
@IBDesignable
class MyView: UIView {
@IBInspectable var fooColor: UIColor
init(frame: CGRect) {
super.init(frame: frame)
// Initialization code
@KevinVitale
KevinVitale / KVNAppDelegate.m
Created April 11, 2014 19:07
UIWindow+ViewController
#import "KVNAppDelegate.h"
#import "UIWindow+ViewController.h"
#pragma mark - KVNAppDelegate
@implementation KVNAppDelegate
// -----------------------------------------------------------------------------
// application:didFinishLaunchingWithOptions:
// -----------------------------------------------------------------------------
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [UIWindow windowWithRootViewController];