Skip to content

Instantly share code, notes, and snippets.

View rtking1993's full-sized avatar

Ryan King rtking1993

  • London
View GitHub Profile
@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 / 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 / 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"),
// MARK: LoginViewController
class LoginViewController: UIViewController, AuthenticationSessionDelegate {
func login(with username: String,
password: String) {
let authenticationSession = AuthenticationSession()
authenticationSession.delegate = self
authenticationSession.performLogin(with: username,
password: password)
@rtking1993
rtking1993 / ClosureLoginExample.swift
Created February 8, 2019 11:48
Simple example of using closures
// MARK: LoginViewController
class LoginViewController: UIViewController {
func login(with username: String,
password: String) {
let authenticationSession = AuthenticationSession()
authenticationSession.performLogin(with: username,
password: password,
completion: { userIdentifier in
@rtking1993
rtking1993 / TorchFunction.swift
Last active February 12, 2019 11:19
Small function to use torch
func setTorch(on: Bool) {
guard let device = AVCaptureDevice.default(for: AVMediaType.video),
device.hasTorch else {
return
}
do {
try device.lockForConfiguration()
if on {
@rtking1993
rtking1993 / Animal.swift
Created June 5, 2019 14:56
Animal model file for sample Safari Animals
// MARK: - Frameworks
import SwiftUI
// MARK: - Animal
struct Animal: Hashable, Identifiable {
// MARK: - Variables
@rtking1993
rtking1993 / Animals+Constants.swift
Created June 5, 2019 14:57
Constants file containing hardcoded animals for Safari Animals
// MARK: - Animal Constants
extension Animal {
static let all: [Animal] = [.lion, .elephant, .giraffe, .zebra]
static let lion = Animal(id: 1, name: "Lion",
description: "Biggest cat in Africa, the king of the jungle.",
imageName: "lion")
static let elephant = Animal(id: 2, name: "Elephant",
description: "Huge plant eating animal with long nose.",