Preparing the incoming ViewController

Code: No segue
Code & Segue: Segue is created in Storyboard, action is invoked in code
Seque: No code. set up completely in Storyboard

CurrentVC -> prepareForSeque -> NextVC

override func prepare(for seque: UIStoryboardSegue, sender: Any?)

	if segue.identifier == "rollDice"{
		let controller = segue.destination as! DiceViewController

		controller.firstValue = randomDiceValue()
		controller.secondValue = randomDiceValue()
	}
self.textField1.delegate = emojiDelegate
self.textField2.delegate = colorizerDelegate
self.textField3.delegate = self
@IBAction func pickAnImage(_ sender: Any){

	let imagePicker = UIImagePickerController()
	imagePicker.delegate = self
	present(imagePicker, animated: true, completion: nil)
}

RollViewController

import UIKit

class RollViewController: UIViewController {

	func randomDiceValue() -> Int {
		let randomValue = 1 + arc4random() % 6

		return Int(randomValue)
	}

	@IBAction func rollTheDice(){

		var controller:DiceViewController
		controller = self.storyboard?.instantiateViewControllerWithIdentifier("DiceViewController") as!
		DiceViewController

		controller.firstValue = self.randomDiceValue()
		controller.secondValue = self.randomDiceValue()

		self.presentViewController(controller, animated: true, completion: nil)
	}
}

Presenting the Dice View

import UIKit

class RollViewController: UIViewController {

	func randomDiceValue() -> Int {

		let randomValue = 1 + arc4random() % 6

		return Int(randomDiceValue) 
	}

	@IBAction func rollTheDice(){
		
	}
}
@IBAction func rollTheDice(){

	let controller: DiceViewController
	controller = storyboard?.instantiateViewController(withIdentifier: "DiceViewController") as! DiceViewController

	controller.firstValue = randomDiceValue()
	controller.secondValue = randomDiceValue()

	present(controller, animated: true, completion: nil)
}

Launch Activity View

import UIKit

class ViewController: UIViewController {

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

	@IBAction func experiment(){
		let image = UIImage()
		let controller = UIActivityViewController(activityItems: [image],
			applicationActivities: nil)
		self.presentViewController(controller, animated: true, completion:nil)
	}
}
@IBAction func experiment(_ sender: Any){
	let nextController = UIImagePickerController()
	self.present(nextController, animated: true, completion: nil)
}

@IBAction func experiment(_ sender: Any){

	let image = UIImage()
	let controller = UIActivityViewController(activityItems: [image],
		self.present(controller, animated: true, completation: nil))
}
import UIKit

class DiceViewController: UIViewController {

	var firstValue: Int?
	var secondValue: Int?

	@IBOutlet var firstDie: UIImageView!
	@IBOutlet var secondDie: UIImageView!

	override func viewWillAppear(animated: Bool){

		if let firstValue = self.firstValue {
			self.firstDie.image = UIImage(named: "d\(firstValue)")
		} else {
			self.firstDie.image = nil;
		}

		if let secondValue = self.secondValue {
			self.secondDie.image = UIImage(named: "d\(secondValue)")
		} else {
			self.secondDie.image = nil
		}

		self.firstDie.alpha = 0
		self.secondDie.alpha = 0
	}
}

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)"
	}
}

Implementation Steps

Name, Service, Conditions, Event Handler
Name:makeUppercase, Realtime Database, Trigger on specific path, makeUppercase handler

const functions = require('firebase-functions');

exports.emojify = functions.database.ref('/messages/{pushId}/text')
	.onWrite(event => {
		if(!event.data.val()|| event.data.previous.val()){
			console.log("not a new write event");
			return;
		}

		console.log("emojifying");

		const originalText = event.data.val();
		const emojifiedText = emojifyText(originalText);

		return event.data.ref.set(emojifiedText);
	});

	function emojifyText(text){
		var emojifiedText = text;
		emojifiedText = emojifiedText.replace(/\blob\b/id, "");
		emojifiedText = emojifiedText.replace(/\blob\b/id, "");
		return emojifiedText;
	}

FirebaseUI Authentication

Adding Sign In
-Email/Password
-Google
-Facebook
-Twitter
-GitHub

mPhotoPickerButton.setOnClickListener(new View.OnClickListener(){
	@Override
	public void onClick(View view){
		Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
		intent.setType("image/jpeg");
		intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
		startActivityForResult(Intent.createChooser(intent, "Complete action using"), RC_PHOTO_PICKER);
	}
});
service firebase.storage {
	match /b/friendlychat-12987.appspot.com/o {
		match /{allPaths=**} {
			allow read, write: if request.auth != null;
		}
	}
}

match /funGifs/cats/{catPics=**}

resource: existing storage data
request: incoming request data

allow read: if request.auth != null && imageId.matches(“.*.gif”)

String name = "Firebase":
name = 3;

var name = "Firebase";
name = 3;

final x = 42;
x = 1024;

const x = 42;
x = 1024

var x = 42;
var y = 1024;

System.out.println("Message");
Log.d(TAG, "Message");

public int multiply(int a, int b){
	return a * b;
}

String[] list = {"apple", "pear", "orange"};

for (int i = 0; i < list.length; i++){
	System.out.println(list[i])
}

Databse implementation

mSendButton.setOnClickListener(new View.OnClickListener(){
	@Override
	public void onClick(View view){
		mMessageEditText.setText("");
	}
});
{
	"rules": {
		".read": true,
		".write": ture
	}
}

Database Security
-Database security rules
-Security rule configuration examples
-Authentication with Firebase

{
	"chat": {
		"messages": {
			"-KS3PV-iwUZp5wkNq70s":{
				"name": "person1",
				"text": "hey!"
			},
			"-KS3PXhIhs8J_inrExy4":{
				"name": "person2",
				"text": "what's up?"
			}
		}
	},
	"special_chat": {
		"messages": {
			"-KR-DwqtKzlWGxSn9P0y":{
				"name": "person1",
				"text":"want to go to the movies?"
			},
			"-KR4tIpWmNn-EYxquSrw": {
				"name": "person3",
				"text": "Yeah! let's meet at 7."
			}
		}
	},
	"users": {
		"uid1":{
			"paid":true
		},
		"uid2": {
			"paid": false
		},
		"uid3": {
			"paid": true
		}
	}

}

Firebase Realtime Database

what is firebase databse?
what can it be used for?
realtime database in action
database structure best practices

“:
“golden”: 1.618
“fog”: true
“palindrome”: “tacocat”
“messages”: “message1”: “name”:”person”, “text”:”Hello?”
“message2”: “name”:”Individual”, “text”:”Hi!”

node should be “child” and “parent

{
	"questions": {
		"ABCDakarandomkey": {
			"question": "Who was the 13th president of the United States?"
			"choice_1": "Millard Fillmore",
			"choice_2": "Zachary Taylor",
			"choice_3": "Franklin Pierce",
			"choice_4": "James K. Polk",
			"answer" :"choice_1"
		},
		"EFGHakarandomkey":{
			"question": "In what year was the first gasoline combustion engine invented?",
			"choice_1":"1769",
			"choice_2":"1886",
			"choice_3":"1807",
			"choice_4":"1864",
			"answer": "choice_4"
		}
	},
	"players":{
		"user_key_1":{
			"name":"Person",
			"opponents":{
				"IJKLakarandomkey":"user_key_2",
				"MNOPakarandomkey":"user_key_6"
			},
			"questions":{
				"ABCDakarandomkey": "Correct",
				"EFGHakarandomkey": "Incorrect"
			}
		},
		"user_key_2": {
			"name": "Mai",
			"opponents": {
				"QRAAakarandomkey": "user_key_1",
				"SQUEakarandomkey": "user_key_6"
			},
			"questions": {
				"ABCDakarandomkey":"Incorrect",
				"EFGHakarandomkey":"Incorrect"
			}
		}
	},
	"opponents": {
		"couple_Key_1": "user_key_1_user_key_2",
		"user_1": "user_key_1",
		"user_2": "user_key_2",
		"winner": "user_key_1"
	}
}