This commit is contained in:
Marc Rousavy
2021-02-19 16:28:05 +01:00
parent b2594f3e12
commit 00c8970366
43 changed files with 2656 additions and 43 deletions

View File

@@ -0,0 +1,26 @@
//
// AVAuthorizationStatus+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 29.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
extension AVAuthorizationStatus {
var descriptor: String {
switch self {
case .authorized:
return "authorized"
case .denied:
return "denied"
case .notDetermined:
return "not-determined"
case .restricted:
return "restricted"
@unknown default:
fatalError("AVAuthorizationStatus has unknown state.")
}
}
}

View File

@@ -0,0 +1,44 @@
//
// AVCaptureColorSpace+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 19.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
extension AVCaptureColorSpace {
init(string: String) throws {
switch string {
case "hlg-bt2020":
if #available(iOS 14.1, *) {
self = .HLG_BT2020
} else {
throw EnumParserError.unsupportedOS(supportedOnOS: "14.1")
}
return
case "p3-d65":
self = .P3_D65
return
case "srgb":
self = .sRGB
return
default:
throw EnumParserError.invalidValue
}
}
var descriptor: String {
switch self {
case .HLG_BT2020:
return "hlg-bt2020"
case .P3_D65:
return "p3-d65"
case .sRGB:
return "srgb"
default:
fatalError("AVCaptureDevice.Position has unknown state.")
}
}
}

View File

@@ -0,0 +1,45 @@
//
// AVCaptureDevice.DeviceType+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 15.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
import Foundation
extension AVCaptureDevice.DeviceType {
var descriptor: String {
if #available(iOS 13.0, *) {
switch self {
case .builtInDualWideCamera:
return "dual-wide-camera"
case .builtInTripleCamera:
return "triple-camera"
case .builtInUltraWideCamera:
return "ultra-wide-angle-camera"
default:
break
}
}
if #available(iOS 11.1, *) {
switch self {
case .builtInTrueDepthCamera:
return "true-depth-camera"
default:
break
}
}
switch self {
case .builtInDualCamera:
return "dual-camera"
case .builtInTelephotoCamera:
return "telephoto-camera"
case .builtInWideAngleCamera:
return "wide-angle-camera"
default:
fatalError("AVCaptureDevice.Position has unknown state.")
}
}
}

View File

@@ -0,0 +1,27 @@
//
// AVCaptureDevice.FlashMode+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 15.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
extension AVCaptureDevice.FlashMode {
init?(withString string: String) {
switch string {
case "on":
self = .on
return
case "off":
self = .off
return
case "auto":
self = .auto
return
default:
return nil
}
}
}

View File

@@ -0,0 +1,40 @@
//
// AVCaptureDevice.Format.AutoFocusSystem+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 29.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
extension AVCaptureDevice.Format.AutoFocusSystem {
init(withString string: String) throws {
switch string {
case "contrast-detection":
self = .contrastDetection
return
case "phase-detection":
self = .phaseDetection
return
case "none":
self = .none
return
default:
throw EnumParserError.invalidValue
}
}
var descriptor: String {
switch self {
case .contrastDetection:
return "contrast-detection"
case .phaseDetection:
return "phase-detection"
case .none:
return "none"
@unknown default:
fatalError("AVCaptureDevice.Format has unknown state.")
}
}
}

View File

@@ -0,0 +1,25 @@
//
// AVCaptureDevice.Position+String.swift
// Cuvent
//
// Created by Marc Rousavy on 15.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
import Foundation
extension AVCaptureDevice.Position {
var descriptor: String {
switch self {
case .back:
return "back"
case .front:
return "front"
case .unspecified:
return "unspecified"
@unknown default:
fatalError("AVCaptureDevice.Position has unknown state.")
}
}
}

View File

@@ -0,0 +1,27 @@
//
// AVCaptureDevice.TorchMode+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 18.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
extension AVCaptureDevice.TorchMode {
init?(withString string: String) {
switch string {
case "on":
self = .on
return
case "off":
self = .off
return
case "auto":
self = .auto
return
default:
return nil
}
}
}

View File

@@ -0,0 +1,29 @@
//
// AVCapturePhotoOutput.QualityPrioritization+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 15.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
import Foundation
@available(iOS 13.0, *)
extension AVCapturePhotoOutput.QualityPrioritization {
init?(withString string: String) {
switch string {
case "speed":
self = .speed
return
case "quality":
self = .quality
return
case "balanced":
self = .balanced
return
default:
return nil
}
}
}

View File

@@ -0,0 +1,55 @@
//
// AVCaptureSession.Preset+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 15.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
import Foundation
extension AVCaptureSession.Preset {
init(withString string: String) throws {
switch string {
case "cif-352x288":
self = .cif352x288
return
case "hd-1280x720":
self = .hd1280x720
return
case "hd-1920x1080":
self = .hd1920x1080
return
case "hd-3840x2160":
self = .hd4K3840x2160
return
case "high":
self = .high
return
case "iframe-1280x720":
self = .iFrame1280x720
return
case "iframe-960x540":
self = .iFrame960x540
return
case "input-priority":
self = .inputPriority
return
case "low":
self = .low
return
case "medium":
self = .medium
return
case "photo":
self = .photo
return
case "vga-640x480":
self = .vga640x480
return
default:
throw EnumParserError.invalidValue
}
}
}

View File

@@ -0,0 +1,61 @@
//
// AVCaptureVideoStabilizationMode+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 29.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
extension AVCaptureVideoStabilizationMode {
init(withString string: String) throws {
switch string {
case "auto":
self = .auto
return
case "cinematic":
self = .cinematic
return
case "cinematic-extended":
if #available(iOS 13.0, *) {
self = .cinematicExtended
return
} else {
throw EnumParserError.unsupportedOS(supportedOnOS: "iOS 13.0")
}
case "off":
self = .off
return
case "standard":
self = .standard
return
default:
throw EnumParserError.invalidValue
}
}
var descriptor: String {
if #available(iOS 13.0, *) {
switch self {
case .cinematicExtended:
return "cinematic-extended"
default:
break
}
}
switch self {
case .auto:
return "auto"
case .cinematic:
return "cinematic"
case .off:
return "off"
case .standard:
return "standard"
default:
fatalError("AVCaptureVideoStabilizationMode has unknown state.")
}
}
}

View File

@@ -0,0 +1,137 @@
//
// AVMetadataObject.ObjectType+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 16.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
import Foundation
extension AVMetadataObject.ObjectType {
init(withString string: String) throws {
switch string {
case "aztec":
self = .aztec
return
case "cat-body":
if #available(iOS 13.0, *) {
self = .catBody
return
} else {
throw EnumParserError.unsupportedOS(supportedOnOS: "13.0")
}
case "code-128":
self = .code128
return
case "code-39":
self = .code39
return
case "code-39-mod-43":
self = .code39Mod43
return
case "code-93":
self = .code93
return
case "data-matrix":
self = .dataMatrix
return
case "dog-body":
if #available(iOS 13.0, *) {
self = .dogBody
return
} else {
throw EnumParserError.unsupportedOS(supportedOnOS: "13.0")
}
case "ean-13":
self = .ean13
return
case "ean-8":
self = .ean8
return
case "face":
self = .face
return
case "human-body":
if #available(iOS 13.0, *) {
self = .humanBody
return
} else {
throw EnumParserError.unsupportedOS(supportedOnOS: "13.0")
}
case "interleaved-2-of-5":
self = .interleaved2of5
return
case "itf-14":
self = .itf14
return
case "pdf-417":
self = .pdf417
return
case "qr":
self = .qr
return
case "salient-object":
if #available(iOS 13.0, *) {
self = .salientObject
return
} else {
throw EnumParserError.unsupportedOS(supportedOnOS: "13.0")
}
case "upce":
self = .upce
return
default:
throw EnumParserError.invalidValue
}
}
var descriptor: String {
if #available(iOS 13.0, *) {
switch self {
case .catBody:
return "cat-body"
case .dogBody:
return "dog-body"
case .humanBody:
return "human-body"
case .salientObject:
return "salient-object"
default: break
}
}
switch self {
case .aztec:
return "aztec"
case .code128:
return "code-128"
case .code39:
return "code-39"
case .code39Mod43:
return "code-39-mod-43"
case .code93:
return "code-93"
case .dataMatrix:
return "data-matrix"
case .ean13:
return "ean-13"
case .ean8:
return "ean-8"
case .face:
return "face"
case .interleaved2of5:
return "interleaved-2-of-5"
case .itf14:
return "itf-14"
case .pdf417:
return "pdf-417"
case .qr:
return "qr"
case .upce:
return "upce"
default:
fatalError("AVMetadataObject.ObjectType has unknown state.")
}
}
}

View File

@@ -0,0 +1,93 @@
//
// AVVideoCodecType+descriptor.swift
// Cuvent
//
// Created by Marc Rousavy on 15.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import AVFoundation
import Foundation
extension AVVideoCodecType {
init?(withString string: String) {
switch string {
case "h264":
self = .h264
return
case "hevc":
self = .hevc
return
case "hevc-alpha":
if #available(iOS 13.0, *) {
self = .hevcWithAlpha
return
} else {
return nil
}
case "jpeg":
self = .jpeg
return
case "pro-res-422":
self = .proRes422
return
case "pro-res-422-hq":
if #available(iOS 13.0, *) {
self = .proRes422HQ
return
} else {
return nil
}
case "pro-res-422-lt":
if #available(iOS 13.0, *) {
self = .proRes422LT
return
} else {
return nil
}
case "pro-res-422-proxy":
if #available(iOS 13.0, *) {
self = .proRes422Proxy
return
} else {
return nil
}
case "pro-res-4444":
self = .proRes4444
return
default:
return nil
}
}
var descriptor: String {
if #available(iOS 13.0, *) {
switch self {
case .hevcWithAlpha:
return "hevc-alpha"
case .proRes422HQ:
return "pro-res-422-hq"
case .proRes422LT:
return "pro-res-422-lt"
case .proRes422Proxy:
return "pro-res-422-proxy"
default:
break
}
}
switch self {
case .h264:
return "h264"
case .hevc:
return "hevc"
case .jpeg:
return "jpeg"
case .proRes422:
return "pro-res-422"
case .proRes4444:
return "pro-res-4444"
default:
fatalError("AVVideoCodecType has unknown state.")
}
}
}

View File

@@ -0,0 +1,27 @@
//
// EnumParserError.swift
// Cuvent
//
// Created by Marc Rousavy on 18.12.20.
// Copyright © 2020 Facebook. All rights reserved.
//
import Foundation
/**
An error raised when the given descriptor (TypeScript string union type) cannot be parsed and converted to a Swift enum.
*/
enum EnumParserError: Error {
/**
Raised when the descriptor is not supported on the current OS.
*/
case unsupportedOS(supportedOnOS: String)
/**
Raised when the descriptor does not match any of the possible values.
*/
case invalidValue
/**
Raised when no descriptor for the given enum is available.
*/
case noDescriptorAvailable
}