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
| 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 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
| 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
| #!/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
| 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
| 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 | |
| typealias JSONData = [String:Any] | |
| struct APIClient { | |
| let session = URLSession.shared | |
| func createRequest(url: URL) -> URLRequest { | |
| return URLRequest(url: url) |
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 http = require('http'); | |
| var server = http.createServer(function(req,res) { | |
| res.writeHead(200); | |
| res.end('Hello world'); | |
| }) | |
| server.listen(8080); |
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 <Foundation/Foundation.h> | |
| @interface APIClient : NSObject | |
| @property(strong,nonatomic) NSString *urlString; | |
| @property(strong, nonatomic) NSURL *url; | |
| @property(strong, nonatomic) NSURLSessionDataTask *downloadTask; | |
| -(void)sendAPICallWith:(void (^)(NSDictionary * dictionary))completionHandler; | |
| -(id)initWithURLString:(NSString *)url; |