Skip to content

Instantly share code, notes, and snippets.

View stulevine's full-sized avatar

Stu Levine stulevine

  • @wildcatproductions.com
  • Auburn Hills, MI
  • 04:33 (UTC -04:00)
View GitHub Profile
// A Playground that shows how to use protocol extensions to do Dependency Injection
import UIKit
import PlaygroundSupport
enum InjectorType: String {
case mainType
case mocType
}
@stulevine
stulevine / ExpandingPillView.swift
Last active April 22, 2017 20:14
Expanding Pill with Number in Swift 3.1
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
extension UIColor {
class func with(hex: UInt, alpha: Float = 1.0) -> UIColor {
return UIColor(colorLiteralRed: Float((hex & 0xFF0000) >> 16)/255.0,
green: Float((hex & 0x00FF00) >> 8)/255.0,
blue: Float((hex & 0x0000FF) >> 0)/255.0,
@stulevine
stulevine / SwiftVCTestWithKVC.swift
Created February 25, 2017 16:44
Swift 3 - Playground showing KVC with dictionary from Quizlet API call
//: Playground - noun: a place where people can play
import UIKit
import Foundation
import PlaygroundSupport
class IndexCardView: UIView {
let topSpacing: CGFloat = 80.0
//: Playground - noun: a place where people can play
import UIKit
var hits = [Int: Bool]()
func collatz(_ n: Int) {
if n == 1 { return }
var new: Int!
if (n % 2) == 0 {
@stulevine
stulevine / swfit_stuff.swift
Created February 25, 2017 13:20
Swift using maps and CustomStringConvertible
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
let a = ["a", "b", "c"]
let b = ["d", "e", "f"]
let c = ["g", "h", "i"]
let aa = [a, b, c]
@stulevine
stulevine / ReduceExample.swift
Created February 25, 2017 13:16
Example of how to use .reduce in Swift 3
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
struct ChartItem {
var label: String = ""
var value: CGFloat = 0.0
}
@stulevine
stulevine / AnimatedBarGraphInStackView.swift
Last active February 25, 2017 13:13
Swift 3 - Playground code
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class BarGraphView: UIView {
lazy var greenBar: UIView = {
let view = UIView(frame: .zero)
view.translatesAutoresizingMaskIntoConstraints = false
@stulevine
stulevine / UIImageFunExtensions.swift
Created February 25, 2017 13:11
Swift 3 - Xcode Playground Code
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
var str = "Hello, playground"
extension UIImage {
class func circle(diameter: CGFloat, color: UIColor) -> UIImage? {
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class IndexCardImageView: UIImageView {
let topSpacing: CGFloat = 80.0
var lineColor = UIColor.clear
var lineWidth: CGFloat = 1.0
//: Playground - noun: a place where people can play
import UIKit
/*
* Description: a String extension to convert roman numerals to their respective integer values
* Synopsis:
* Any of the letters representing numbers in the Roman numerical system:
*
* I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1,000.