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
import Foundation | |
import RxSwift | |
import RxCocoa | |
class NewsManager { | |
typealias NewsLoadState = LoadState<ArticlesResponse> | |
enum LoadError: Error { | |
case unknownError | |
} |
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
import Foundation | |
enum LoadState<T> { | |
case loading | |
case updating | |
case loaded(response: T) | |
case failed(error: Error) | |
} |
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
extension ViewController: UITableViewDataSource { | |
... | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let tableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! NewsTableViewCell | |
let article = articles[indexPath.row] | |
tableViewCell.titleLabel.text = article.title | |
tableViewCell.contentLabel.text = article.content |
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
import UIKit | |
import Alamofire | |
class ImageManager { | |
private let session = Alamofire.Session() | |
static let shared = ImageManager() | |
func load(url: URLConvertible, completionHandler: @escaping (UIImage) -> Void) -> Void { |
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
extension ViewController: UITableViewDataSource { | |
func numberOfSections(in tableView: UITableView) -> Int { | |
return 1 | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return articles.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
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
extension ViewController: UITableViewDelegate { | |
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
let article = articles[indexPath.row] | |
present(SFSafariViewController(url: article.url), animated: true, completion: nil) | |
} | |
} |
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
// TODO: update the API key | |
private let apiKey: String = "c8707b3709a34bbe90837f63c71537ed" | |
private let path: String = "https://newsapi.org/v2/top-headlines?apiKey=\(apiKey)&country=us" | |
enum ClientError: Error { | |
case missingResponseData | |
} | |
class NewsClient { | |
func headlines() -> Single<ArticlesResponse> { |
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
import UIKit | |
import RxSwift | |
import SafariServices | |
class ViewController: UIViewController { | |
private let disposeBag = DisposeBag() | |
private let client = NewsClient() | |
private var articles: [Article] = [] | |
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
import Foundation | |
class Article: Decodable { | |
let title: String | |
let description: String? | |
let url: URL | |
let urlToImage: String? | |
let content: String? | |
} |
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
vertices, triangles = read_obj("teapot.obj") | |
x = vertices[:,0] | |
y = vertices[:,1] | |
z = vertices[:,2] | |
ax = plt.axes(projection='3d') | |
ax.set_xlim([-3, 3]) | |
ax.set_ylim([-3, 3]) | |
ax.set_zlim([0, 3]) | |
ax.plot_trisurf(x, z, triangles, y, shade=True, color='white') |