Skip to content

Instantly share code, notes, and snippets.

View jamesrochabrun's full-sized avatar
🇵🇪

James Rochabrun jamesrochabrun

🇵🇪
View GitHub Profile
class ViewController: UIViewController {
@IBOutlet weak var redView: UIView! {
didSet {
//redView.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
}
}
@IBOutlet weak var greenView: UIView!
//Reduce function
let sum = [1, 2, 3, 4, 5].reduce(0, +)
let multiply = [1, 2, 3, 4].reduce(1, *)
//strings
let sentence = ["My", "last", "name", "is", "very", "hard", "to", "pronounce"].reduce("", {$0 + $1 + " "})
//filter with closures!
func filterWithPredicate(closure: (Int) -> Bool, numbers: [Int]) -> [Int] {
var filteredNumbers = [Int]()
for num in numbers {
//perfor some condition
//closures are passed as parameter and executed inside the function
if closure(num) {
filteredNumbers.append(num)
}
protocol Ordered {
//this is "Self" requirement and is a placeholder for the type that uses the protocol
func preceds(other: Self) -> Bool
}
struct Number: Ordered {
var value: Double = 0
func preceds(other: Number) -> Bool {
return self.value < other.value
}
//
// CustomSegmentedControl.swift
// CustomSegmentedControl
//
// Created by james rochabrun on 8/22/17.
// Copyright © 2017 james rochabrun. All rights reserved.
import Foundation
import UIKit
//
// Reusable.swift
// CollectionReusableProtocol
//
// Created by James Rochabrun on 7/24/17.
// Copyright © 2017 James Rochabrun. All rights reserved.
//
import Foundation
import UIKit
{"assets":[],"layers":[{"ddd":0,"ind":0,"ty":1,"nm":"NULL CONTROL","ks":{"o":{"k":0},"r":{"k":0},"p":{"k":[43.32,27.28,0]},"a":{"k":[60,60,0]},"s":{"k":[37.12,37.12,100]}},"ao":0,"sw":120,"sh":120,"sc":"#ffffff","ip":7,"op":158,"st":-18,"bm":0,"sr":1},{"ddd":0,"ind":1,"ty":4,"nm":"SPLASH","parent":0,"ks":{"o":{"k":100},"r":{"k":0},"p":{"k":[-12.25,-77.75,0]},"a":{"k":[0,0,0]},"s":{"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ks":{"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[226.276,402.972],[204.956,375.07]],"c":false}},"nm":"Path 1","mn":"ADBE Vector Shape - Group"},{"ind":1,"ty":"sh","ks":{"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[140.865,418.419],[140.981,377.25]],"c":false}},"nm":"Path 2","mn":"ADBE Vector Shape - Group"},{"ind":2,"ty":"sh","ks":{"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[59,401.199],[77.484,375.07]],"c":false}},"nm":"Path 3","mn":"ADBE Vector Shape - Group"},{"ty":"tm","s":{"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p8
{"assets":[],"layers":[{"ddd":0,"ind":0,"ty":3,"nm":"Rotator","ks":{"o":{"k":0},"r":{"k":[{"i":{"x":[0.56],"y":[1]},"o":{"x":[0.634],"y":[0]},"n":["0p56_1_0p634_0"],"t":-90,"s":[0],"e":[190.7]},{"i":{"x":[0.562],"y":[1]},"o":{"x":[0.398],"y":[0]},"n":["0p562_1_0p398_0"],"t":-76,"s":[190.7],"e":[176.1]},{"i":{"x":[0.684],"y":[1]},"o":{"x":[0.31],"y":[0]},"n":["0p684_1_0p31_0"],"t":-68.5,"s":[176.1],"e":[181.8]},{"i":{"x":[0.684],"y":[1]},"o":{"x":[0.438],"y":[0]},"n":["0p684_1_0p438_0"],"t":-54,"s":[181.8],"e":[180]},{"i":{"x":[0.733],"y":[0.733]},"o":{"x":[0.385],"y":[0.385]},"n":["0p733_0p733_0p385_0p385"],"t":-38,"s":[180],"e":[180]},{"i":{"x":[0.092],"y":[1]},"o":{"x":[0.406],"y":[0]},"n":["0p092_1_0p406_0"],"t":2,"s":[180],"e":[167.9]},{"i":{"x":[0.341],"y":[1]},"o":{"x":[0.6],"y":[0]},"n":["0p341_1_0p6_0"],"t":7,"s":[167.9],"e":[363]},{"i":{"x":[0.462],"y":[1]},"o":{"x":[0.167],"y":[0]},"n":["0p462_1_0p167_0"],"t":25,"s":[363],"e":[360]},{"t":32}]},"p":{"k":[200.5,149.375,0]},"a":{"k":[60,60,0]},"s":{"k"
{"assets":[],"layers":[{"ddd":0,"ind":0,"ty":3,"nm":"Rotator","ks":{"o":{"k":0},"r":{"k":[{"i":{"x":[0.56],"y":[1]},"o":{"x":[0.634],"y":[0]},"n":["0p56_1_0p634_0"],"t":19,"s":[0],"e":[190.7]},{"i":{"x":[0.562],"y":[1]},"o":{"x":[0.398],"y":[0]},"n":["0p562_1_0p398_0"],"t":33,"s":[190.7],"e":[176.1]},{"i":{"x":[0.684],"y":[1]},"o":{"x":[0.31],"y":[0]},"n":["0p684_1_0p31_0"],"t":40.5,"s":[176.1],"e":[181.8]},{"i":{"x":[0.684],"y":[1]},"o":{"x":[0.438],"y":[0]},"n":["0p684_1_0p438_0"],"t":55,"s":[181.8],"e":[180]},{"i":{"x":[0.733],"y":[0.733]},"o":{"x":[0.385],"y":[0.385]},"n":["0p733_0p733_0p385_0p385"],"t":71,"s":[180],"e":[180]},{"i":{"x":[0.092],"y":[1]},"o":{"x":[0.406],"y":[0]},"n":["0p092_1_0p406_0"],"t":111,"s":[180],"e":[167.9]},{"i":{"x":[0.341],"y":[1]},"o":{"x":[0.6],"y":[0]},"n":["0p341_1_0p6_0"],"t":116,"s":[167.9],"e":[363]},{"i":{"x":[0.462],"y":[1]},"o":{"x":[0.167],"y":[0]},"n":["0p462_1_0p167_0"],"t":134,"s":[363],"e":[360]},{"t":141}]},"p":{"k":[200.5,149.375,0]},"a":{"k":[60,60,0]},"s":{"k
//: Playground - noun: a place where people can play
import UIKit
//swift functions are first class citizens which means that we can use them in many of the same operations which we use native types in.
//FUNCTIONS AS PROPERTIES
func sayHi(_ greeting: String) {
print(greeting)