Skip to content

Instantly share code, notes, and snippets.

View rorodriguez116's full-sized avatar

Rolando Rodríguez rorodriguez116

  • United Kingdom
View GitHub Profile
@rorodriguez116
rorodriguez116 / SendMessageUseCase.swift
Last active April 27, 2020 17:50
SendMessageUseCase example
import Foundation
struct Message {
var id: String
var recieverId: String
var senderId: String
var content: String
}
protocol MessageRepository {
@rorodriguez116
rorodriguez116 / ModuleProvider.swift
Last active April 28, 2020 23:52
Quick example of Module Provider
import ModuleProvider
import UIKit
import Foundation
enum Module {
case none
case messages(YourConfigObject)
case feed
case profile
}
@rorodriguez116
rorodriguez116 / checkCameraPermissions.swift
Created October 16, 2020 03:40
Function to check the appropriate camera permissions have been provided.
// MARK: Checks for permisions, setup obeservers and starts running session
public func checkForPermissions() {
/*
Check the video authorization status. Video access is required and audio
access is optional. If the user denies audio access, CameraService won't
record audio during movie recording.
*/
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized:
// The user has previously granted access to the camera.
@rorodriguez116
rorodriguez116 / PProperties_CS.swift
Last active October 22, 2020 16:05
Published properties UI will react to from CamerService
public class CameraService {
typealias PhotoCaptureSessionID = String
// MARK: Observed Properties UI must react to
// 1.
@Published public var flashMode: AVCaptureDevice.FlashMode = .off
// 2.
@Published public var shouldShowAlertView = false
// 3.
@rorodriguez116
rorodriguez116 / RProperties_CS.swift
Last active October 22, 2020 16:17
Remaining properties for CameraService
// ...
// MARK: Alert properties
public var alertError: AlertError = AlertError()
// MARK: Session Management Properties
// 9. The capture session.
public let session = AVCaptureSession()
@rorodriguez116
rorodriguez116 / Photo+AlertError.swift
Last active October 22, 2020 15:22
AlertError and Photo struct declarations.
public struct Photo: Identifiable, Equatable {
// The ID of the captured photo
public var id: String
// Data representation of the captured photo
public var originalData: Data
public init(id: String = UUID().uuidString, originalData: Data) {
self.id = id
self.originalData = originalData
}
@rorodriguez116
rorodriguez116 / checkForPermissions.swift
Created October 22, 2020 16:20
Function to check camera access permissions.
// MARK: Checks for user's permisions
public func checkForPermissions() {
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized:
// The user has previously granted access to the camera.
break
case .notDetermined:
/*
The user has not yet been presented with the option to grant
@rorodriguez116
rorodriguez116 / captureSessionConfig.swift
Created October 22, 2020 17:19
Capture session configuration
// MARK: Session Managment
// Call this on the session queue.
/// - Tag: ConfigureSession
private func configureSession() {
if setupResult != .success {
return
}
session.beginConfiguration()
@rorodriguez116
rorodriguez116 / StartCaptureSession.swift
Created October 23, 2020 00:32
Starts the capture session
/// - Tag: Start capture session
public func start() {
// We use our capture session queue to ensure our UI runs smoothly on the main thread.
sessionQueue.async {
if !self.isSessionRunning && self.isConfigured {
switch self.setupResult {
case .success:
self.session.startRunning()
self.isSessionRunning = self.session.isRunning
@rorodriguez116
rorodriguez116 / Stop_CaptureSession.swift
Created October 23, 2020 20:05
Stops camera video capture session
/// - Tag: Stop capture session
public func stop(completion: (() -> ())? = nil) {
sessionQueue.async {
if self.isSessionRunning {
if self.setupResult == .success {
self.session.stopRunning()
self.isSessionRunning = self.session.isRunning
if !self.session.isRunning {