Storyboard

import UIKit

class ViewController: UIViewController {

	var count = 0
	var label:UILabel!

	func incrementCount(){
		self.count++
		self.label.text = "\(self.count)"
	}
}
import UIKit

class ViewController: UIViewController {

	@IBOutlet weak var colorView: UIView!
	@IBOutlet weak var redControl: UISwitch!
	@IBOutlet weak var greenControl: UISwitch!
	@IBOutlet weak var blueControl: UISwitch!

	override func viewDidLoad(){
		super.viewDidLoad()
	}

	@IBAction func changeColorComponent(sender: AnyObject){
		let r: CGFloat = self.redControl.on ? 1:0
		let g: CGFloat = self.greenControl.on ? 1:0
		let b: CGFloat = self.blueControl.on ? 1 : 0

		colorView.backgroundColor = UIColor(red: r, green: g, blue: b, alpha:1)
	}
}
@IBAction func experiment(){
	let nextController = UIImagePickerController()
	self.presentViewController(nextController, animated: true, completion:nil)
}

Map

1.Outlets and Actions
2.Presenting View Controllers
3.The Delegate Pattern
4.Tables
5.Navigation
6.MemeMe Techniques

Clike counter
ViewController -> UIViewm UILabel, UIButton

import UIKit

class ViewController: UIViewController {
	override func viewDidLoad(){
		super.viewDidLoad()
		var label = UILabel()
		label.frame = CGRectMake(150, 150, 60, 60)
		label.text = "0"

		self.view.addSubview(label)

		var button = UIButton()
		button.frame = CGRectMake(150, 250, 60, 60)
		button.setTitle("click", forState: .Normal)
		button.setTitleColor(UIColor.blueColor(), forState: .Normal)
		self.view.addSubview(button)
	}
}
import UIKit

class ViewController: UIViewController {

	var count = 0
	var label:UILabel!

	override func viewDidLoad(){
		super.viewDidLoad()
		var label = UILabel()
		label.frame = CGRectMake(150, 150, 60, 60)
		label.text = "0"

		self.view.addSubview(label)
		self.label = label

		var button = UIButton()
		button.frame = CGRectMake(150, 250, 60, 60)
		button.setTitle("click", forState: .Normal)
		button.setTitleColor(UIColor.blueColor(), forState: .Normal)
		self.view.addSubview(button)

		button.addTarget(self, action: "incrementCount", forControlEvents:
			UIControlEvents.TouchUpInside)
	}
	func incrementCount(){
		self.count++
		self.label.text = "\(self.count)"
	}
}

latitude

latitude
https://www.esrl.noaa.gov/gmd/grad/solcalc/

Shadows and Trigonometry
18m, 10m, β
β = arctan(18/10) in degrees = 60.9°

w = 25m / tan(1.3°) = 1101m

MC = 40,000Km / 3.68, MC = 10,900K

distance to the moon
10900 = πd
d = 3470km
tan(0.5°)=3470 / L
L = 3470 / tan(0.5) = 398,000 km

distance to the sun
cos α = 400,000/L
L = 400,000/ cos89.853°
L = 156,000,000 km

Delegation

AVAudioRecorder
Record VC

func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool){
	if flag {
		performSegue(withIdentifier: "stopRecording", sender: audioRecorder.url)
	} else {
		print("recording was not successful")
	}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?){
	if segue.identifier == "stopRecording"{
		let laySoundsVC = segue.destination as! PlaySoundsViewController
		let recordedAudioURL = sender as! url
		playSoundVC.recordedAudioURL = recordedAudioURL
	}
}

Stack Views: Horizontal, Vertical
-alignment, distribution, spacing

AVAudioEngine

var dollars:Int = 10
var cents:Int = 50
var amount = "$\(dollars).\(cents)"
print(amount)

dollars = 19
centsd = 99
amount = "$\(dollars).\(cents)"
print(amout)

func printMoneyString(dollars:Int, cents:Int){
	print("$\(dollars).\(cents)")
}

Tour of Xcode

Document Outline in Xcode

Model View Controller
view(UIView, UILabel, UIButton), controller, model

AutoLayout Basics

@IBOutlet weak var recordButton: UIButton!
@IBOutlet weak var recordingLabel: UILabel!
@IBOutlet weak var resumeButton: UIButton!
@IBOutlet weak var resumeLabel: UILabel!
@IBOutlet weak var pauseButton: UIButton!
@IBOutlet weak var pauseLabel: UILabel!
@IBOutlet weak var stopButton: UIButton!
@IBOutlet weak var stopLabel: UILabel!

@IBOutlet func recordButtonPressed(sender: UIButton){
	// ...
}

ViewController and Multiple Views
Not Running, Inactive, Active, Background, Suspended

Audio in iOS
Pitch Perfect App, AVFoundation, Core Audio, Audio Hardware

import AVFoundation

class ViewController: UIViewController {
	var audioRecorder: AVAudioRecorder!

	@IBAction func recordAudio(_ sender: AnyObject){
		recordingLabel.text = "Recording in progress"
		stopRecordingButton.isEnabled = true
		recordButton.isEnabled = false

		let dirPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask, true)[0] as String
		let recordingName = "recordedVoice.wav"
		let pathArray = [dirPath, recordingName]
		let filePath = URL(string: pathArray.joined(separator: "/"))

		let session = AVAudioSession.sharedInstance()
		try! session.setCategory(AVAudioSessionCategoryPlayAndRecord, with:AVAudioSessionCategoryOptions.defaultToSpeaker)

		try! audioRecorder = AVAudioRecorder(url: filePath!, settings: [:])
		audioRecorder.isMeteringEnabled = true
		audioRecorder.prepareToRecord()
		audioRecorder.record()
	}
}

Introduction X-code

import UIKit

var x: Int = 42
var x = 42
let y = 100

var myString = "Hello"

// Control Flow
if x < 50 {
	print("X is less than 50")
} else {
	print("X is greater than or equal to 50")
}

// Classes
class ViewController: UIViewController {
	// Instance Variables go here
	// Class functions go here
}

// Functions
func printHello(){
	print("Hello")
}

printHello()

func printHelloMessage(helloString: String){
	print(helloString)
}

printHelloMessage("Oi!")

Closures

Closures include:
global functions, nested functions, and closure expressions

Nested functions
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-ID178

closure expression- an unnamed, self contained block of code
closure expression are used to specify an action to be executed some time in the future.

var bids = [48, 75, 63, 52, 68]
var orderedBids = bids.sort( {(bid1: Int, bid2: Int) -> Bool in
	return bid2 > bid1
})

print(orderedBids)

Closures typically take the form:
{(parameters) -> return type in
statements to execute
}

var birthYears = [2004, 2011, 2007, 2005, 2002]
var reverseChronologicalYears = birthYears.sort({ (year1: Int, year2: Int) -> Bool interface EarthquakeActivity extends Parent {
	return year1 > year2
}
})

Protocols and Extensions

Protocols

Adopting a protocol is like signing a contract to implement every method on the list.

import UIKit

protocol Souschef {
	func chop(vegetable: String) -> String
	func rinse(vegetable: String) -> String
}

class Roommate: Souschef {
	var hungry = true
	var name: String

	init(hungry:Bool, name: String){
		self.hungry = hungry
		self.name = name
	}

	func chop(vegetable: String) -> String {
		return "She's choppin' \(vegetable)!"
	}

	func rinse(vegetable: String) -> String {
		return "The \(vegetable) is so fresh and so clean"
	}
}
class DinnerCrew {
	var members: [Souschef]

	init(members: [Souschef]){
		self.members = members
	}
}
protocol DirtyDeeds {
	func cheat()
	func steal()
}

class Minion: DirtyDeeds {
	var name: String

	init(name:String){
		self.name = name
	}

	func cheat(){
		println("Mwa haha!")
	}

	func steal(){
		println("Mwa haha!")
	}
}

class DinnerCrew {
	var members: [Souschef]

	init(members: [Souschef]){
		self.members = members
	}
}

protocol Souschef {
	func chop(vegetable: String) -> String
	func rinse(vegetable: String) -> String
}

var deviousDinnerCrew = DinnerCrew(members: [Minion]())

Andrew Bancroft’s Swift blog
http://www.andrewcbancroft.com/

Enums and Structs

Enums and Structs
{
case red
case blue
case green
}

import UIKit

enum PrimaryColor {
	case red
	case blue
	case yellow
}
enum Aunties {
	case Aime, Billie, Diane, Gail, Janie, Pam
}
enum AmericanLeagueWest: String {
	case As = "Oakland"
	case Astros = "Houston"
	case Angels = "Los Angeles"
	case Mariners = "Seatle"
	case Rangers = "Arlington"
}
enum CaliforniaPark {
	case Yosemite, DeathValley, Lesson, Sequoia
}

var warning = ""
var destination = CaliforniaPark.Yosemite

switch destination {
	case.Yosemite:
		warning = "Beware of agressive bears!"
	case.DeathValley:
		warning = "Beware of dehydration!"
	case.Lasson:
		warning = "Watch out for boiling pools!"
}
struct PictureFrame {
	var width = 5
	var height = 7
	var thickness: Double = 1.5

	var area: Int {
		get {
			return width * height
		}
	}
}
var frame = PictureFrame(width: 3, height: 5, thickness: 0.5)
var frameForMom = frame
frameForMom.width = 5
frameForMom.height = 7
frame.width
frame.height

class ClassyPictureFrame {
	var width = 5
	var height = 7
	var thickness: Double = 1.5

	var area: Int {
		get {
			return (width * height) / 2
		}
	}

	init(width: Int, height: Int, thickness: Double){
		self.width = width
		self.height = height
		self.thickness = thickness
	}
}

var classyFrame = ClassyPictureFrame(width: 3, height: 5, thickness: 0.5)
var classyFrameForMom = classyFrame
var darkColors = Laundry(temperature: 70, speed: "medium")
var darkDelicates = darkColors
darkDelicates.speed = "low"
darkColors.speed
 Triangle {
 	let angles = [30, 60, 90]
 	let sides = [3,4,5]
 }

 UIImagePickerControllerSourceType : Int {
 	case PhotoLibrary
 	case Camera
 	case SavedPhotosAlbum
 }

 struck Name {
 	var firstName: String
 	var lastName: String
 }

 enum Subject {
 	case Math
 	case English
 	case Spanish
 	case Science
 }

Classes, Properties, and Methods

import UIKit

class Movie {
	let title: String
	let director: String
	let releaseYear: Int

	init(title: String, director: String, releaseYear: Int){
		self.title = title
		self.director = director
		self.releaseYear = releaseYear
	}
}
class MovieArchive {
	var movies:[Movie]

	func filterByYear(year:Int) -> [Movie]{
		var filteredArray = [Movie]()
		for movie in self.movies {
			if movie.releaseYear == year {
				filteredArray.append(movie)
			}
		}
		return filteredArray
	}

	init(movies:[Movie]){
		self.movies = movies
	}
}
import UIKit

class ViewController: UIViewController {

	var count = 0
	var label:UILabel!

	override func viewDidLoad(){
		super.viewDidLoad()

		// Label
		var label = UILabel()
		label.frame = CGRectMake(150, 150, 60, 60)
		label.text = "0"
		self.view.addSubview(label)
		self.label = label
		// Button
		var button = UIButton()
		button.addTarget(self, action: "incrementCount", forControlEvents: UIControlEvents.TouchUpInside)
		self.view.addSubview(button)
		button.frame = CGRectMake(150, 250, 60, 60)
		button.setTitle("Click", forState: .Normal)
		button.setTitleColor(UIColor.blueColor(), forState:.Normal)
	}

	@IBAction func incrementCount(){
		self.count++
		self.label.text = "\(self.count)"
	}
}

Access Control
Level, Class, App/Framework, Work
public: Y Y Y
internal: Y Y N
private Y N N

class Movie {
	let title: String
	let director: String
	let releaseYear: Int

	init(title: String, director: String, releaseYear: Int){
		self.title = title
		self.director = director
		self.releaseYear = releaseYear
	}
}

var thursdayNightMovie = Movie(title: "Point Break", director: "Kathryn Bigelow", releaseYear: 1991)
thursdayNightMovie.title