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
// | |
// ComputationalGeometry.swift// | |
// Created by James Rochabrun on 5/2/17. | |
// | |
// | |
import Foundation | |
//types of algorhitms | |
//1) constant -> 1 (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
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 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 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 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 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 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 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) | |
} |
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
//1) What is ARC and how does it work? | |
//Every time you create a new instance of a class, ARC allocates a chunk of memory to store information about that instance. | |
//This memory holds information about the type of the instance, together with the values of any stored properties associated | |
//with that instance. | |
//Additionally, when an instance is no longer needed, ARC frees up the memory used by that instance so that the memory | |
//can be used for other purposes instead. This ensures that class instances do not take up space in memory when they are | |
//no longer needed. | |
//However, if ARC were to deallocate an instance that was still in use, it would no longer be possible to access that | |
//instance’s properties, or call that instance’s methods. Indeed, if you tried to access the instance, your app would most likely crash. |
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 Person: Comparable { | |
var birthDate: NSDate? | |
let name: String | |
init(name: String) { | |
self.name = name | |
} | |
static func ==(lhs: Person, rhs: Person) -> Bool { | |
return lhs.birthDate === rhs.birthDate || lhs.birthDate?.compare(rhs.birthDate as! Date) == .orderedSame |