This file contains hidden or 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) |
This file contains hidden or 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
// | |
// ComputationalGeometry.swift// | |
// Created by James Rochabrun on 5/2/17. | |
// | |
// | |
import Foundation | |
//types of algorhitms | |
//1) constant -> 1 (1) |
This file contains hidden or 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
var arr = ["a", "abc", "aabc", "aabbc", "aaabbbcc", "bacc", "bbcc", "bbbccc", "cb", "cbb", "cbbc", "d" , "defff", "deffz"] | |
func binarySearch(_ array: [String], value: String) -> String { | |
var firstIndex = 0 | |
var lastIndex = array.count - 1 | |
var wordToFind = "Not founded" | |
var count = 0 | |
This file contains hidden or 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
//1 Download the assets | |
https://www.yelp.com/developers/display_requirements | |
//2 enum to enumerate assets | |
enum ReviewIcon: NSNumber { | |
case zeroStar | |
case oneStar | |
case oneAndHalfStar | |
case twoStar |
This file contains hidden or 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 | |
//GENERICS | |
//passing the reference in a method using the inout keyword | |
func swapInts(_ a: inout Int, _ b: inout Int) { | |
let tempA = a | |
a = b |
This file contains hidden or 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
//Given this classes | |
class Address { | |
var buildingNumber: String? | |
var street: String? | |
} | |
class Residence { | |
var numberOfRooms = 1 | |
var address: Address? | |
} | |
class Resident { |
This file contains hidden or 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
//OPTIONAL BINDING | |
let weatherDictionary: [String: String] = ["currentWeather" : "22.4", "weeklyWeather" : "25.9"] | |
if let weekly = weatherDictionary["weeklyWeather"] { | |
print(weekly) | |
} | |
//prints 25.9 | |
//DOWNSIDES OF USING IF LET AND WHY GUARD SOLVE THIS | |
struct Friend { |
This file contains hidden or 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 Person { | |
let name: String | |
var apartment: Apartment? | |
init(name: String) { | |
self.name = name | |
} | |
deinit { | |
print("\(name) is being deinitialized, memory deallocated") |
This file contains hidden or 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 | |
//fizbuzz | |
var oneHundred = [Int]() | |
for i in 1...100 { | |
oneHundred.append(i) | |
} |