Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan King rtking1993

  • London
View GitHub Profile
@rtking1993
rtking1993 / NotificationLoginExample.swift
Created Feb 8, 2019
Simple example of how to use notifications to pass data
View NotificationLoginExample.swift
// 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 Feb 8, 2019
Example of basic authentication situation
View BasicLoginExample.swift
// 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 Apr 14, 2018
A view controller that displays CAShapeLayers inside a UIView
View ShapeViewController.swift
// MARK: Frameworks
import UIKit
// MARK: ViewController
class ShapeViewController: UIViewController {
// MARK: Outlets
@rtking1993
rtking1993 / UIBezierPath+Extension.swift
Last active Apr 14, 2018
UIBezierPath extension to create some icons and shapes
View UIBezierPath+Extension.swift
// MARK: Frameworks
import UIKit
// MARK: UIBezierPath Methods
extension UIBezierPath {
convenience init(homeIn rect: CGRect) {
self.init()
@rtking1993
rtking1993 / Utils.swift
Last active Apr 14, 2018
Utils to convert degrees to radians
View Utils.swift
// MARK: Frameworks
import UIKit
// MARK: Helper Methods
func radians(from degrees: CGFloat) -> CGFloat {
return ((degrees * .pi) / 180)
}
@rtking1993
rtking1993 / Article.swift
Created Apr 8, 2018
Article model struct with Decodable protocol
View Article.swift
// MARK: Frameworks
import Foundation
// MARK: Article
struct Articles: Decodable {
let count: Int
let results: [Article]
@rtking1993
rtking1993 / ArticleRemote.swift
Created Apr 8, 2018
Remote class that allows us to connect to NYT articles API
View ArticleRemote.swift
// 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 Apr 8, 2018
View Controller for showing a list of New York Times articles
View ArticleViewController.swift
// MARK: Frameworks
import UIKit
// MARK: ArticleViewController
class ArticleViewController: UIViewController {
// MARK: Outlets
@rtking1993
rtking1993 / ItemsMainViewControllerBody.swift
Created Mar 30, 2018
The body methods of the MainViewController for our dynamic list
View ItemsMainViewControllerBody.swift
// 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 Mar 30, 2018
A remote class of type Items
View ItemsRemote.swift
// MARK: Frameworks
import Foundation
import FirebaseDatabase
// MARK: ItemsRemote
class ItemsRemote {
// MARK: Constants