Skip to content

Instantly share code, notes, and snippets.

View casademora's full-sized avatar

Saul Mora casademora

View GitHub Profile
//: Playground - noun: a place where people can play
//To try out this code, copy and paste into a new Xcode playground.
import UIKit
class Operation: NSObject
{
let nextOperation: Operation?
init(next: Operation? = nil)
{
@casademora
casademora / gist:9581611f69a59a511992389658c59e00
Created October 28, 2016 03:39
Dynamic Swift Demo Source
//: Playground - noun: a place where people can play
import UIKit
public protocol Maths
{
func doMath(left: Double, right: Double) -> Double
}
class Addition: NSObject, Maths
@casademora
casademora / gist:c4b19d8503767479c0e05a836de4aa4c
Last active August 26, 2016 02:39
Animation behaviors demo from Shanghai Cocoaheads
//
// ViewController.swift
// BehaviorsDemo
//
// Created by Saul Mora on 8/25/16.
// Copyright © 2016 Magical Panda. All rights reserved.
//
import UIKit
@casademora
casademora / gist:443dad5d16d095f8747a
Created July 9, 2015 19:14
Implement a method incorrectly by using generic rather than protocol parameter crashes clang compiler
protocol Thing {
var name: String { get }
}
protocol UsingThing {
func doSomething(with: Thing)
}
struct Test: UsingThing {
@casademora
casademora / gist:3b784e57bd09c0bc9147
Last active May 17, 2017 01:08
Simple Outline for Cache layer in Swift
//: Playground - noun: a place where people can play
import UIKit
protocol DataSource {
func fetchValue() -> String?
}
protocol DataSourceCacheStrategy {
func retrieve<T>(from: [DataSource], using: DataSource -> T?) -> T?
@casademora
casademora / gist:753834752f3cb43b9b44
Last active February 25, 2019 21:22
Private func in swift are hidden from the ObjC runtime
import Foundation
class Testing : NSObject
{
private func privateWork() {
}
internal func internalWork(){
}
@casademora
casademora / gist:f115102b2e6530e2554c
Last active September 2, 2015 19:13
Rebuild Core Data Entities Script
#!/bin/sh
## $1 is the path to the model relative to the project dir
## $2 is the name of the model file
##TODO, make the path optional and the model file required
mogen=`which mogenerator`
PlistBuddy=`which PlistBuddy`
if [[ -x $1 ]]; then
@casademora
casademora / gist:40b960d49e057ecb3684
Last active August 29, 2015 14:04
Managed Object initializer
class CustomObject : NSManagedObject
{
init(inContext context:NSManagedObjectContext = SingletonContextStorage.context)
{
let klass = CustomObject.self
let entity = NSEntityDescription.entityForName(klass.entityName(), inManagedObjectContext: context)
super.init(entity: entity, insertIntoManagedObjectContext: context)
}
}
@casademora
casademora / gist:d06e69288fb24c9ace6e
Created July 14, 2014 15:20
Extension to writeTo NSOutputStream
extension String
{
func writeTo(outputStream:NSOutputStream)
{
if let data = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
{
let bytes = ConstUnsafePointer<UInt8>(data.bytes)
outputStream.write(bytes, maxLength: data.length)
}
}
@implementation NSNumber (PandaHelpers)
- (void) mgp_times:(void(^)(NSInteger))thingToDo;
{
NSAssert(thingToDo, @"No operation to perform");
for (NSInteger i = 0; i < [self integerValue]; i++)
{
thingToDo(i);
}