Skip to content

Instantly share code, notes, and snippets.

@freedom27
freedom27 / Protocols_and_trees.swift
Last active December 16, 2015 17:05
Experimenting with Swift's protocols and trees
protocol HasName {
var name: String { get }
}
protocol HasSubNodes: HasName {
var subNodes: [HasName] { get }
}
protocol HasData: HasName {
@freedom27
freedom27 / String+Enhancement.swift
Last active February 9, 2016 18:50
Working with swift's Strings made easy
import Foundation
extension String {
func substringWithRange(r: Range<Int>) -> String {
return substringWithRange(Range(start: startIndex.advancedBy(r.startIndex), end: startIndex.advancedBy(r.endIndex)))
}
func substringToIndex(i: Int) -> String {
return substringToIndex(startIndex.advancedBy(i))
protocol Disposable {
func dispose()
func addToDisposablesBag(bag: DisposablesBag)
}
extension Disposable {
func addToDisposablesBag(bag: DisposablesBag) {
bag.add(self)
}
}
//
// Promise.swift
// PiGuardMobile
//
// Created by Stefano Vettor on 06/04/16.
// Copyright © 2016 Stefano Vettor. All rights reserved.
//
import Foundation
//: Playground - noun: a place where people can play
import Foundation
protocol Neuron {
var weights: [Double] {get}
func feedforward(input: [Double]) -> Double
func activation(input: Double) -> Double
}
//
// UIBarButtonItem+Badge.swift
// PiGuardMobile
//
// Created by Stefano Vettor on 12/04/16.
// Copyright © 2016 Stefano Vettor. All rights reserved.
//
import UIKit