TorchMode 2.swift 637 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import UIKit
  2. import AVFoundation
  3. /// Wrapper around `AVCaptureTorchMode`.
  4. public enum TorchMode {
  5. case on
  6. case off
  7. /// Returns the next torch mode.
  8. var next: TorchMode {
  9. switch self {
  10. case .on:
  11. return .off
  12. case .off:
  13. return .on
  14. }
  15. }
  16. /// Torch mode image.
  17. var image: UIImage {
  18. switch self {
  19. case .on:
  20. return imageNamed("flashOn")
  21. case .off:
  22. return imageNamed("flashOff")
  23. }
  24. }
  25. /// Returns `AVCaptureTorchMode` value.
  26. var captureTorchMode: AVCaptureDevice.TorchMode {
  27. switch self {
  28. case .on:
  29. return .on
  30. case .off:
  31. return .off
  32. }
  33. }
  34. }