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
Objective challenge: | |
Q1) Pair off, and with a peer, each choose a design pattern and think of an instance you’ve used it code you’ve written or have seen it used in UIKit. | |
A1) We have used the MVC pattern in our beginning projects. We used this design pattern in our first build week project. | |
Objective challenge: | |
Q2)Look through the documentation and find at least one UIKit class that uses the singleton pattern. | |
A2) App Delegate | |
Objective challenge: | |
Q3) Think about a time we’ve used the facade pattern before. Are there places that we could have used it to write better code but didn’t? Discuss with a peer. |
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
import UIKit | |
func makeChangeAsString(fromAmount: Double, withCost: Double) -> String { | |
let change = fromAmount - withCost | |
let dollars = Int(change / 1) | |
var cents = change.truncatingRemainder(dividingBy: 1) | |
let quarters = Int(cents / 0.25) | |
cents -= Double(quarters) * 0.25 | |
let dimes = Int(cents / 0.10) |
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
import UIKit | |
func bubbleSort<AnyItem: Comparable>(_ array: [AnyItem] ) -> [AnyItem] { | |
var newArray = array | |
var temp: AnyItem | |
for i in 0..<newArray.count - 1 { | |
for j in (i + 1)..<newArray.count { | |
if newArray[i] > newArray[j] { | |
//swap | |
temp = newArray[i] |
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
extension String { | |
func anotherContains(sentence: String) -> Bool { | |
if self.lowercased().range(of: sentence.lowercased()) != nil { | |
return true | |
} else { | |
return false | |
} | |
} | |
} |
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
// | |
// NotebooksListViewController.swift | |
// Mooskine | |
// | |
// Created by Josh Svatek on 2017-05-31. | |
// Copyright © 2017 Udacity. All rights reserved. | |
// | |
import UIKit | |
import CoreData |
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
func expandTheNumber(_ number: Int) -> [Int] { | |
var copyOfNum = number | |
var zeroPlaces = 1 | |
var newArray: [Int] = [] | |
if number < 10 { | |
newArray.append(number) | |
} else { | |
while copyOfNum >= 1 { | |
newArray.insert(((copyOfNum % 10) * zeroPlaces), at: 0) |
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
import UIKit | |
class DetailCocktailViewController: UIViewController { | |
// MARK: - IBOutlets | |
@IBOutlet var drinkNameLabel: UILabel! | |
@IBOutlet var imageView: UIImageView! | |
@IBOutlet var IngredientsTextView: UITextView! | |
@IBOutlet var instructionsTextView: UITextView! | |
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
// | |
// CocktailResults.swift | |
// cocktailMaker | |
// | |
// Created by Claudia Contreras on 3/25/20. | |
// Copyright © 2020 thecoderpilot. All rights reserved. | |
// | |
import Foundation |
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
// | |
// CocktailResultController.swift | |
// cocktailMaker | |
// | |
// Created by Claudia Contreras on 3/25/20. | |
// Copyright © 2020 thecoderpilot. 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
import UIKit | |
func canBePalindrome(string: String) -> Bool { | |
//lowercase the string | |
string.lowercased() | |
//Reverse it in a new string | |
let newString = String(string.reversed()) | |
//compare the values |
NewerOlder