Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan King rtking1993

  • London
View GitHub Profile
@rtking1993
rtking1993 / CircleImage.swift
Last active Jun 5, 2019
CircleImage supporting view which is displayed within Safari Animals
View CircleImage.swift
// MARK: - Frameworks
import SwiftUI
// MARK: - CircleImage
struct CircleImage: View {
var image: Image
var body: some View {
@rtking1993
rtking1993 / AnimalRow.swift
Last active Jun 5, 2019
Animal Row for each animal in Safari Animals
View AnimalRow.swift
// MARK: - Frameworks
import SwiftUI
// MARK: - AnimalRow
struct AnimalRow: View {
var animal: Animal
var body: some View {
@rtking1993
rtking1993 / AnimalDetail.swift
Last active Jun 5, 2019
Animal Details view for Safari Animals
View AnimalDetail.swift
// MARK: - Frameworks
import SwiftUI
// MARK: - AnimalDetail
struct AnimalDetail: View {
var animal: Animal
var body: some View {
@rtking1993
rtking1993 / AnimalList.swift
Last active Jun 5, 2019
Animal List for Safari Animals
View AnimalList.swift
// MARK: - Frameworks
import SwiftUI
// MARK: - AnimalList
struct AnimalList: View {
var body: some View {
NavigationView {
List(Animal.all) { animal in
@rtking1993
rtking1993 / Animals+Constants.swift
Created Jun 5, 2019
Constants file containing hardcoded animals for Safari Animals
View Animals+Constants.swift
// 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.",
@rtking1993
rtking1993 / Animal.swift
Created Jun 5, 2019
Animal model file for sample Safari Animals
View Animal.swift
// MARK: - Frameworks
import SwiftUI
// MARK: - Animal
struct Animal: Hashable, Identifiable {
// MARK: - Variables
View JailbreakDetector.swift
extension UIDevice {
private class JailbreakDetector {
static var current: JailbreakDetector = JailbreakDetector()
lazy var containsSuspiciousFiles: Bool = {
return (["/Applications/Cydia.app",
"/Library/MobileSubstrate/MobileSubstrate.dylib",
"/bin/bash",
"/usr/sbin/sshd",
@rtking1993
rtking1993 / TorchFunction.swift
Last active Feb 12, 2019
Small function to use torch
View TorchFunction.swift
func setTorch(on: Bool) {
guard let device = AVCaptureDevice.default(for: AVMediaType.video),
device.hasTorch else {
return
}
do {
try device.lockForConfiguration()
if on {
@rtking1993
rtking1993 / ClosureLoginExample.swift
Created Feb 8, 2019
Simple example of using closures
View ClosureLoginExample.swift
// MARK: LoginViewController
class LoginViewController: UIViewController {
func login(with username: String,
password: String) {
let authenticationSession = AuthenticationSession()
authenticationSession.performLogin(with: username,
password: password,
completion: { userIdentifier in
View DelegateLoginExample.swift
// 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)