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
import UIKit | |
typealias JSON = [String : Any] | |
fileprivate let imageCache = NSCache<NSString, UIImage>() | |
extension NSError { | |
static func generalParsingError(domain: String) -> Error { | |
return NSError(domain: domain, code: 400, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("Error retrieving data", comment: "General Parsing Error Description")]) | |
} | |
} |
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
import UIKit | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
class APIClient { | |
typealias JSON = [String: Any] | |
static func search(for query: String, page: Int, completion: @escaping (_ responseObject: JSON?, _ error: Error?) -> Void) { |
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
#!/usr/bin/env python* | |
# -*- coding: UTF-8 -*- | |
import requests | |
import sys | |
import re | |
class WebCrawler: | |
def __init__(self): |
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
enum Transaction { | |
case deposit, withdraw | |
} | |
class Bank { | |
typealias Account = (String, Double) | |
typealias AccountTransaction = (Double, Account) -> Account | |
static func deposit(amount : Double, account : (name : String, balance : Double)) -> Account { |
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
import UIKit | |
typealias JSON = [String: Any] | |
final class iTunesAPIClient: NSObject { | |
var activeDownloads: [String: Download]? | |
weak var defaultSession: URLSession? = URLSession(configuration: .default) | |
// MARK: - Main session used |
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
func testDataStore() { | |
let dataSource = iTrackDataStore(searchTerm: "new") | |
let expect = expectation(description: "Data store calls APIClient to access server data and returns iTrack data array.") | |
dataSource.searchForTracks { tracks, error in | |
XCTAssert(tracks?.count == 49) | |
expect.fulfill() | |
} |
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
import UIKit | |
typealias TreeNode = TreeElement<Int> | |
enum Color { case r, b } | |
indirect enum TreeElement<T: Comparable> { | |
case empty | |
case node(Color, TreeElement<T>, T, TreeElement<T>) |
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
import UIKit | |
func insertionSort(values: [Int]) { | |
var valuesArray = values | |
for i in 1...valuesArray.count - 1 { | |
let nextItem = valuesArray[i] | |
var currentIndex = i - 1 | |
while currentIndex >= 0 && valuesArray[currentIndex] > nextItem { | |
valuesArray[currentIndex + 1] = valuesArray[currentIndex] |
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
import UIKit | |
class ViewController: UIViewController { | |
let viewOne = UIView() | |
let viewTwo = UIView() | |
let intermediaryView = UIView() | |
let viewSuper = UIView() | |
override func viewDidLoad() { |
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
import UIKit | |
protocol ImageDownloadProtocol { | |
func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void) | |
} | |
extension ImageDownloadProtocol { | |
func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void) { | |
let session = URLSession(configuration: .default) | |
DispatchQueue.global(qos: .background).async { |