Impressia/Vernissage/Extensions/String+Exif.swift

28 lines
672 B
Swift
Raw Normal View History

2023-01-08 14:50:37 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import Foundation
extension String {
func calculateExifNumber() -> String? {
guard self.contains("/") else {
return self
}
let parts = self.split(separator: "/")
guard parts.count == 2 else {
return nil
}
if let first = Int(parts[0]), let second = Int(parts[1]) {
let calculated = Double(first) / Double(second)
return String(calculated.rounded(toPlaces: 2))
}
return nil
}
}