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
| switch(url.parse(request.url).pathname) { | |
| case '/p1': | |
| if (!error) { | |
| response.end(data); | |
| } else { | |
| console.log(error); | |
| } | |
| case '/p2': | |
| if (!error) { | |
| response.end("Page 2"); |
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] | |
| // search functionality stuff |
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
| }).listen(port, (error) => { | |
| if (error) { | |
| console.log('error ${ error }') | |
| } | |
| console.log('listening on ${ port }') | |
| }); |
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 Math { | |
| func add(_ intOne: Int, _ intTwo: Int) -> Int { | |
| return intOne + intTwo | |
| } | |
| } |
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 XCTest | |
| @testable import ExampleProject | |
| class ExampleProjectTests: XCTestCase { | |
| override func setUp() { | |
| super.setUp() | |
| } | |
| override func tearDown() { |
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 XCTest | |
| import AVFoundation | |
| @testable import Musicly | |
| class MusiclyTests: XCTestCase { | |
| // Boiler plate | |
| func testDataStore() { | |
| let dataSource = iTrackDataStore(searchTerm: "new") |
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() { | |
| // Setup test | |
| dataStore.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
| func testDataStore() { | |
| // Setup | |
| // Run test | |
| waitForExpectations(timeout: 4) { error in | |
| if let error = error { | |
| XCTFail("waitForExpectationsWithTimeout error: \(error)") | |
| } | |
| } |
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
| protocol ImageDownloadProtocol { | |
| func downloadImage(from url: URL, completion: @escaping (UIImage?) -> 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
| extension ImageDownloadProtocol { | |
| func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void) { | |
| let session = URLSession(configuration: .default) | |
| DispatchQueue.global(qos: .background).async { | |
| print("In background") | |
| session.dataTask(with: URLRequest(url: url)) { data, response, error in | |
| if error != nil { | |
| print(error?.localizedDescription ?? "Unknown error") | |
| } | |
| if let data = data, let image = UIImage(data: data) { |