Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

xplat (#4439) #1851

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Foundation
public extension Data {
public var imageFormat: ImageFormat? {
switch self.first {
case 0xFF?:
case 0xFF:
return EncodedImageFormat.jpeg
case 0x89?:
case 0x89:
return EncodedImageFormat.png
default:
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public extension XCTestCase {

let transformations = options.transformations
if transformations.resizeRequirement == nil && transformations.cropRequirement == nil &&
options.encodeRequirement?.mode != .lossy && transformations.rotateRequirement == nil &&
options.outputImageFormat == fromImageData.imageFormat {
options.encodeRequirement?.mode != .lossy && transformations.rotateRequirement == nil &&
options.outputImageFormat == fromImageData.imageFormat {
XCTAssertEqual(fromImageData, toImageData)
} else {
XCTAssertNotEqual(fromImageData, toImageData)
Expand Down
2 changes: 1 addition & 1 deletion ios/SpectrumKitSample/SpectrumKitSample-iOS/Alerts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct Alerts {
static let configurationGeneralDefaultBackgroundColor = AlertContent(title: NSLocalizedString("Select default background color", comment: "Configuration general background color title"),
message: nil,
optionsType: ConfigurationViewModel.DefaultBackgroundColor.self)

static let configurationPngCompressionLevel = AlertContent(title: NSLocalizedString("Select PNG compression level", comment: "Configuration PNG compression level"),
message: nil,
optionsType: ConfigurationViewModel.CompressionLevel.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ final class ConfigurationViewController: UIViewController, ConfigurationViewMode
self.jpegUseOptimizeScanSwitch.isOn = viewModel.jpeg.useOptimizeScan
self.jpegUseDcScanOptionSwitch.isOn = viewModel.jpeg.useCompatibleDCScanOption
self.jpegUsePsnrQuantTableSwitch.isOn = viewModel.jpeg.usePSNRQuantTable

self.pngUseInterlacingSwitch.isOn = viewModel.png.useInterlacing
self.pngCompressionLevelButton.setTitle(viewModel.png.compressionLevel.title, for: .normal)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ extension ConfigurationViewModel {

static var allValues: [DefaultBackgroundColor] = [.black, .white, .blue, .red, .green]
}

enum CompressionLevel: Int, AlertOptions {
case `default`
case none
case bestSpeed
case bestCompression

var rawValue: Int {
switch self {
case .default:
Expand All @@ -107,7 +107,7 @@ extension ConfigurationViewModel {
return PngCompressionLevelBestCompression
}
}

init?(rawValue: Int) {
switch rawValue {
case PngCompressionLevelNone:
Expand All @@ -120,12 +120,12 @@ extension ConfigurationViewModel {
self = .default
}
}

// MARK: AlertOptions

var title: String {
let title: String

switch self {
case .default:
return NSLocalizedString("Default", comment: "Png default compression level")
Expand All @@ -136,17 +136,16 @@ extension ConfigurationViewModel {
case .bestCompression:
title = NSLocalizedString("Best compression", comment: "Png best compression level")
}

let formatString = NSLocalizedString("%@ (%d)", comment: "Png compression level format String")
return String(format: formatString, title, rawValue)
}

var isAvailable: Bool {
return true
}

static var allValues: [CompressionLevel] = [.default, .none, .bestSpeed, .bestCompression]

}

enum WebpMethod: Int, AlertOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import Foundation

protocol ConfigurationViewModelDelegate: class {
protocol ConfigurationViewModelDelegate: AnyObject {
func viewModelDidUpdate(_ viewModel: ConfigurationViewModel)
}

protocol ConfigurationViewModelInternalDelegate: class {
protocol ConfigurationViewModelInternalDelegate: AnyObject {
func internalViewModelDidUpdate(_ viewModel: Any)
}

Expand Down Expand Up @@ -132,7 +132,7 @@ final class ConfigurationViewModel: ConfigurationViewModelInternalDelegate {
self.delegate?.internalViewModelDidUpdate(self)
}
}

var compressionLevel: CompressionLevel {
get { return CompressionLevel(rawValue: self.configuration.compressionLevel)! }
set {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import UIKit

protocol ImageDifferenceViewControllerDelegate: class {
protocol ImageDifferenceViewControllerDelegate: AnyObject {
func imageDifferenceViewControllerDidTapCloseButton(_ imageDifferenceViewController: ImageDifferenceViewController)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Foundation
import UIKit.UIImage

protocol ImageDifferenceViewModelDelegate: class {
protocol ImageDifferenceViewModelDelegate: AnyObject {
func imageDifferenceViewModelDidChange(_ viewModel: ImageDifferenceViewModel)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import UIKit

protocol ImagePickerCoordinatorDelegate: class {
protocol ImagePickerCoordinatorDelegate: AnyObject {
func imagePickerCoordinator(_ imagePickerCoordinator: ImagePickerCoordinator, didPickMedia source: ImageSource)
func imagePickerCoordinator(_ imagePickerCoordinator: ImagePickerCoordinator, didFailToPickImageWith error: Swift.Error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import UIKit

protocol PickerButtonDelegate: class {
protocol PickerButtonDelegate: AnyObject {
func pickerButton(_ pickerButton: UIButton, didPick option: Int)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class SprectrumViewController: UIViewController, SpectrumViewModelDelegate
super.prepare(for: segue, sender: sender)

switch segue.identifier.flatMap(Segue.init(rawValue:)) {
case .showImageDifference?:
case .showImageDifference:
guard
let viewController = segue.destination as? ImageDifferenceViewController,
let viewModel = sender as? ImageDifferenceViewModel
Expand All @@ -80,7 +80,7 @@ final class SprectrumViewController: UIViewController, SpectrumViewModelDelegate
viewController.viewModel = viewModel
viewController.delegate = self

case .showConfiguration?:
case .showConfiguration:
guard let viewController = segue.destination as? ConfigurationViewController else {
fatalError("Unexpected viewController for: \(String(describing: segue.identifier))")
}
Expand Down
24 changes: 12 additions & 12 deletions ios/SpectrumKitSample/SpectrumKitSample-iOS/SpectrumViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Photos
import UIKit.UIImage

protocol SpectrumViewModelDelegate: class {
protocol SpectrumViewModelDelegate: AnyObject {
func viewModelDidUpdate(_ viewModel: SpectrumViewModel)
func viewModel(_ viewModel: SpectrumViewModel, didFailTranscodingWith error: Swift.Error)
func viewModelDidFinishTranscoding(_ viewModel: SpectrumViewModel)
Expand Down Expand Up @@ -149,17 +149,17 @@ final class SpectrumViewModel: NSObject {
inputType: self.inputType,
outputType: self.outputType,
completion: { [weak self] result in
guard let strongSelf = self else { return }
strongSelf.isTranscoding = false
guard let strongSelf = self else { return }
strongSelf.isTranscoding = false

switch result {
case let .success(imageRepresentation):
strongSelf.transcodedImageRepresentation = imageRepresentation
strongSelf.delegate?.viewModelDidFinishTranscoding(strongSelf)
case let .error(error):
strongSelf.delegate?.viewModel(strongSelf, didFailTranscodingWith: error)
}
})
switch result {
case let .success(imageRepresentation):
strongSelf.transcodedImageRepresentation = imageRepresentation
strongSelf.delegate?.viewModelDidFinishTranscoding(strongSelf)
case let .error(error):
strongSelf.delegate?.viewModel(strongSelf, didFailTranscodingWith: error)
}
})
}

func makeConfigurationViewModel() -> ConfigurationViewModel {
Expand All @@ -172,7 +172,7 @@ final class SpectrumViewModel: NSObject {
return try ImageDifferenceViewModel(sourceImage: self.source.image,
transcodedImageData: data,
imageFormat: self.outputFormat)
case .bitmap(_)?, nil:
case .bitmap, nil:
throw Error.unsupportedBitmapOutput
}
}
Expand Down