This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rapide | |
.https | |
.host("openexhangerates.org") | |
.path("/api/convert/2000/GBP/EUR") | |
.authorization(.none) | |
.params(["app_id":"XYZ"]) | |
.execute(.get, decoding: String.self, customErrorType: MyErrorType.self) | |
.sink { completion in | |
if case let .failure(error) = completion { | |
if let err = error as? MyErrorType { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CameraView: View { | |
@StateObject var model = CameraViewModel() | |
@State var currentZoomFactor: CGFloat = 1.0 | |
var captureButton: some View { | |
Button(action: { | |
model.capturePhoto() | |
}, label: { | |
Circle() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func set(zoom: CGFloat){ | |
let factor = zoom < 1 ? 1 : zoom | |
let device = self.videoDeviceInput.device | |
do { | |
try device.lockForConfiguration() | |
device.videoZoomFactor = factor | |
device.unlockForConfiguration() | |
} | |
catch { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Device Configuration | |
/// - Tag: ChangeCamera | |
public func changeCamera() { | |
// MARK: Here disable all camera operation related buttons due to configuration is due upon and must not be interrupted | |
DispatchQueue.main.async { | |
self.isCameraButtonDisabled = true | |
} | |
// | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import AVFoundation | |
final class CameraViewModel: ObservableObject { | |
private let service = CameraService() | |
@Published var photo: Photo! | |
@Published var showAlertError = false | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
struct CameraPreview: UIViewRepresentable { | |
// 1. | |
class VideoPreviewView: UIView { | |
override class var layerClass: AnyClass { | |
AVCaptureVideoPreviewLayer.self | |
} | |
var videoPreviewLayer: AVCaptureVideoPreviewLayer { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Capture Photo | |
/// - Tag: CapturePhoto | |
public func capturePhoto() { | |
if self.setupResult != .configurationFailed { | |
self.isCameraButtonDisabled = true | |
sessionQueue.async { | |
if let photoOutputConnection = self.photoOutput.connection(with: .video) { | |
photoOutputConnection.videoOrientation = .portrait |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Photos | |
class PhotoCaptureProcessor: NSObject { | |
lazy var context = CIContext() | |
private(set) var requestedPhotoSettings: AVCapturePhotoSettings | |
private let willCapturePhotoAnimation: () -> Void | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// - 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// - 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 |
NewerOlder