Skip to content

Instantly share code, notes, and snippets.

View rtking1993's full-sized avatar

Ryan King rtking1993

  • London
View GitHub Profile
@rtking1993
rtking1993 / CalculatorInteractorTests.swift
Created March 28, 2018 18:12
An XCTestCase class that tests the logic of calculator operations
// MARK: Frameworks
import XCTest
// MARK: CalculatorInteractorTests
class CalculatorInteractorTests: XCTestCase {
// MARK: Variables
@rtking1993
rtking1993 / CalculatorInteractorTestSnippet.swift
Created March 28, 2018 18:19
Just one function of my test class to test the logic of my calculator operations
// MARK: Frameworks
import XCTest
// MARK: CalculatorInteractorTests
class CalculatorInteractorTests: XCTestCase {
// MARK: Variables
@rtking1993
rtking1993 / Item.swift
Created March 30, 2018 13:37
A simple Firebase model for an item
import FirebaseDatabase
// MARK: Item
enum ItemParameters: String {
case item = "item"
}
// MARK: Item
@rtking1993
rtking1993 / ItemsPropertyObserver.swift
Created March 30, 2018 13:42
A simple example of a property observer
// MARK: Variables
var items: [Item] = [] {
didSet {
myTableView.reloadData()
}
}
@rtking1993
rtking1993 / ItemsTableViewDataSource.swift
Created March 30, 2018 13:44
Datasource methods for a UITableView
// MARK: UITableViewDataSource Methods
extension MainViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
let item = items[indexPath.row]
cell.textLabel?.text = item.item
@rtking1993
rtking1993 / ItemsRemote.swift
Created March 30, 2018 13:47
A remote class of type Items
// MARK: Frameworks
import Foundation
import FirebaseDatabase
// MARK: ItemsRemote
class ItemsRemote {
// MARK: Constants
@rtking1993
rtking1993 / ItemsMainViewControllerBody.swift
Created March 30, 2018 13:51
The body methods of the MainViewController for our dynamic list
// MARK: View Methods
override func viewDidLoad() {
super.viewDidLoad()
loadItems()
}
// MARK: Action Methods
@IBAction func add(_ sender: Any?) {
guard let itemText = addTextField.text else {
@rtking1993
rtking1993 / ArticleViewController.swift
Created April 8, 2018 12:32
View Controller for showing a list of New York Times articles
// MARK: Frameworks
import UIKit
// MARK: ArticleViewController
class ArticleViewController: UIViewController {
// MARK: Outlets
@rtking1993
rtking1993 / ArticleRemote.swift
Created April 8, 2018 12:39
Remote class that allows us to connect to NYT articles API
// MARK: Frameworks
import Foundation
// MARK: ArticleRemote
class ArticleRemote {
static func retrieveArticles(completion: @escaping(_ articles: Articles) -> Void) {
let session = URLSession(configuration: .default)
let apiURL: URL = URL(string: "https://api.nytimes.com/svc/mostpopular/v2/mostviewed/Technology/1.json")!
@rtking1993
rtking1993 / Article.swift
Created April 8, 2018 12:40
Article model struct with Decodable protocol
// MARK: Frameworks
import Foundation
// MARK: Article
struct Articles: Decodable {
let count: Int
let results: [Article]