This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
@IBOutlet weak var redView: UIView! { | |
didSet { | |
//redView.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) | |
} | |
} | |
@IBOutlet weak var greenView: UIView! | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 + " "}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CustomSegmentedControl.swift | |
// CustomSegmentedControl | |
// | |
// Created by james rochabrun on 8/22/17. | |
// Copyright © 2017 james rochabrun. All rights reserved. | |
import Foundation | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Reusable.swift | |
// CollectionReusableProtocol | |
// | |
// Created by James Rochabrun on 7/24/17. | |
// Copyright © 2017 James Rochabrun. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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) |