Remove unused API

This commit is contained in:
Miwa / Ensan
2024-03-30 02:01:11 +09:00
parent f29d46d316
commit 5e96958577
8 changed files with 1 additions and 234 deletions

View File

@ -1,69 +0,0 @@
//
// AppVersion.swift
// azooKey
//
// Created by ensan on 2022/07/02.
// Copyright © 2022 ensan. All rights reserved.
//
import Foundation
/// AppVersion is a struct that represents a version of an app.
/// It is a wrapper of String that conforms to Codable, Equatable, Comparable, Hashable, LosslessStringConvertible, CustomStringConvertible.
/// It is initialized with a string that represents a version of an app.
/// The string must be in the format of "major.minor.patch".
/// The string must not contain any other characters than numbers and dots.
public struct AppVersion: Codable, Equatable, Comparable, Hashable, LosslessStringConvertible, CustomStringConvertible, Sendable {
/// ParseError is an enum that represents an error that occurs when parsing a string to an AppVersion.
private enum ParseError: Error {
case nonIntegerValue
}
/// Initializes an AppVersion with a string that represents a version of an app.
public init?(_ description: String) {
if let versionSequence = try? description.split(separator: ".").map({ (value: Substring) throws -> Int in
guard let value = Int(value) else { throw ParseError.nonIntegerValue }
return value
}) {
if versionSequence.count < 1 {
self.majorVersion = 0
} else {
self.majorVersion = versionSequence[0]
}
if versionSequence.count < 2 {
self.minorVersion = 0
} else {
self.minorVersion = versionSequence[1]
}
if versionSequence.count < 3 {
self.patchVersion = 0
} else {
self.patchVersion = versionSequence[2]
}
} else {
return nil
}
}
/// Compares two AppVersions.
public static func < (lhs: AppVersion, rhs: AppVersion) -> Bool {
for (l, r) in zip([lhs.majorVersion, lhs.minorVersion, lhs.patchVersion], [rhs.majorVersion, rhs.minorVersion, rhs.patchVersion]) {
if l == r {
continue
}
return l < r
}
return false
}
public var majorVersion: Int
public var minorVersion: Int
public var patchVersion: Int
public var description: String {
"\(majorVersion).\(minorVersion).\(patchVersion)"
}
}

View File

@ -8,13 +8,6 @@
import Algorithms
import Foundation
@resultBuilder
public struct ArrayBuilder {
public static func buildBlock<T>(_ values: T...) -> [T] {
values
}
}
public extension Sequence {
/// Returns a sequence that contains the elements of this sequence followed by the elements of the given sequence.
/// - Parameters:

View File

@ -1,18 +0,0 @@
//
// CodableSupport.swift
// azooKey
//
// Created by ensan on 2021/03/17.
// Copyright © 2021 ensan. All rights reserved.
//
import Foundation
public extension Encodable {
/// Encodes this value into the given container.
/// - Parameters:
/// - container: The container to encode this value into.
func containerEncode<CodingKeys: CodingKey>(container: inout KeyedEncodingContainer<CodingKeys>, key: CodingKeys) throws {
try container.encode(self, forKey: key)
}
}

View File

@ -74,15 +74,6 @@ public extension StringProtocol {
return String(utf16CodeUnits: result, count: result.count)
}
/// Returns an Index value that is the specified distance from the start index.
/// - Parameter:
/// - offset: The distance to offset from the start index.
/// - Returns: An Index value that is the specified distance from the start index.
@inlinable
func indexFromStart(_ offset: Int) -> Index {
self.index(self.startIndex, offsetBy: offset)
}
// FIXME: Migration
// :
/*

View File

@ -1,64 +0,0 @@
//
// UserDefaultsManager.swift
//
//
// Created by ensan on 2023/07/21.
//
import Foundation
public protocol UserDefaultsKeys: RawRepresentable where RawValue == String {
associatedtype Manager: UserDefaultsManager
init(keyPath: PartialKeyPath<Manager>)
}
public protocol UserDefaultsManager {
associatedtype Keys: UserDefaultsKeys where Keys.Manager == Self
var userDefaults: UserDefaults { get }
mutating func update<T: Codable>(_ value: KeyPath<Self, T>, newValue: T)
mutating func update<T: Codable>(_ value: KeyPath<Self, T>, process: (inout T) -> Void)
}
public extension UserDefaultsManager {
mutating func update<T: Codable>(_ value: KeyPath<Self, T>, newValue: T) {
if let value = value as? WritableKeyPath {
self[keyPath: value] = newValue
update(value: value)
}
}
mutating func update<T: Codable>(_ value: KeyPath<Self, T>, process: (inout T) -> Void) {
if let value = value as? WritableKeyPath {
process(&self[keyPath: value])
update(value: value)
}
}
}
public extension UserDefaultsManager {
mutating func update(value: WritableKeyPath<Self, some Codable>) {
do {
let data = try JSONEncoder().encode(self[keyPath: value])
let key = Keys(keyPath: value)
userDefaults.set(data, forKey: key.rawValue)
} catch {
debug(error)
}
}
static func load<T: StaticInitialValueAvailable>(key: Keys, userDefaults: UserDefaults) -> T {
if let value = userDefaults.data(forKey: key.rawValue) {
do {
let value = try JSONDecoder().decode(T.self, from: value)
return value
} catch {
debug(error)
}
}
return T.initialValue
}
}
public protocol StaticInitialValueAvailable: Codable {
static var initialValue: Self {get}
}

View File

@ -1,5 +1,5 @@
//
// Modify.swift
// WithMutableValue.swift
// azooKey
//
// Created by ensan on 2022/10/10.

View File

@ -1,57 +0,0 @@
//
// AppVersionTests.swift
// azooKeyTests
//
// Created by ensan on 2022/12/19.
// Copyright © 2022 ensan. All rights reserved.
//
@testable import SwiftUtils
import XCTest
final class AppVersionTests: XCTestCase {
func testInitFromString() throws {
do {
let version = AppVersion("1.9.3")
XCTAssertNotNil(version)
XCTAssertEqual(version!.majorVersion, 1)
XCTAssertEqual(version!.minorVersion, 9)
XCTAssertEqual(version!.patchVersion, 3)
}
do {
let version = AppVersion("1.10")
XCTAssertNotNil(version)
XCTAssertEqual(version!.majorVersion, 1)
XCTAssertEqual(version!.minorVersion, 10)
XCTAssertEqual(version!.patchVersion, 0)
}
do {
let version = AppVersion("1")
XCTAssertNotNil(version)
XCTAssertEqual(version!.majorVersion, 1)
XCTAssertEqual(version!.minorVersion, 0)
XCTAssertEqual(version!.patchVersion, 0)
}
do {
let version = AppVersion("X")
XCTAssertNil(version)
}
}
func testComparable() throws {
XCTAssertTrue(AppVersion("1.9.1")! < AppVersion("1.10")!)
XCTAssertTrue(AppVersion("1.7")! < AppVersion("1.7.1")!)
XCTAssertTrue(AppVersion("1.10")! < AppVersion("2.1")!)
XCTAssertFalse(AppVersion("1.9.1")! < AppVersion("1.9.1")!)
XCTAssertFalse(AppVersion("2.5")! < AppVersion("2.4.9")!)
XCTAssertTrue(AppVersion("2.5")! > AppVersion("2.4.9")!)
XCTAssertTrue(AppVersion("3.1")! > AppVersion("1.4.9")!)
XCTAssertFalse(AppVersion("1.9.1")! > AppVersion("1.9.1")!)
XCTAssertFalse(AppVersion("1.9.1")! > AppVersion("1.10")!)
XCTAssertFalse(AppVersion("1.7")! > AppVersion("1.7.1")!)
XCTAssertFalse(AppVersion("1.10")! > AppVersion("2.1")!)
}
}

View File

@ -22,13 +22,4 @@ final class StringExtensionTests: XCTestCase {
XCTAssertEqual("".toHiragana(), "")
XCTAssertEqual("これはろん".toHiragana(), "これはろん")
}
func testIndexFromStart() throws {
do {
let string = "ア❤️‍🔥ウ😇オ"
XCTAssertEqual(string[string.indexFromStart(3)], "😇")
XCTAssertEqual(string[string.indexFromStart(4)], "")
}
}
}