Skip to content

Instantly share code, notes, and snippets.

View rtking1993's full-sized avatar

Ryan King rtking1993

  • London
View GitHub Profile
@rtking1993
rtking1993 / NotificationLoginExample.swift
Created February 8, 2019 11:29
Simple example of how to use notifications to pass data
// MARK: LoginViewController
class LoginViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(handleLogin(notification:)),
name: Notification.Name("UserIdentifier"),
@rtking1993
rtking1993 / BasicLoginExample.swift
Last active February 8, 2019 11:18
Example of basic authentication situation
// MARK: LoginViewController
class LoginViewController: UIViewController {
func login(with username: String,
password: String) {
let authenticationSession = AuthenticationSession()
authenticationSession.performLogin(with: username,
password: password)
}
@rtking1993
rtking1993 / ShapeViewController.swift
Last active April 14, 2018 15:07
A view controller that displays CAShapeLayers inside a UIView
// MARK: Frameworks
import UIKit
// MARK: ViewController
class ShapeViewController: UIViewController {
// MARK: Outlets
@rtking1993
rtking1993 / UIBezierPath+Extension.swift
Last active April 14, 2018 18:04
UIBezierPath extension to create some icons and shapes
// MARK: Frameworks
import UIKit
// MARK: UIBezierPath Methods
extension UIBezierPath {
convenience init(homeIn rect: CGRect) {
self.init()
@rtking1993
rtking1993 / Utils.swift
Last active April 14, 2018 18:05
Utils to convert degrees to radians
// MARK: Frameworks
import UIKit
// MARK: Helper Methods
func radians(from degrees: CGFloat) -> CGFloat {
return ((degrees * .pi) / 180)
}
@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]
@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 / 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 / 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 / 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