diff --git a/.swiftlint.yml b/.swiftlint.yml deleted file mode 100644 index c62ba71..0000000 --- a/.swiftlint.yml +++ /dev/null @@ -1,11 +0,0 @@ -opt_in_rules: - - sorted_imports - -disabled_rules: - - line_length - - nesting - -indentation: 2 - -excluded: - - .build \ No newline at end of file diff --git a/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDETemplateMacros.plist b/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDETemplateMacros.plist deleted file mode 100644 index e4792b4..0000000 --- a/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDETemplateMacros.plist +++ /dev/null @@ -1,10 +0,0 @@ - - - - - FILEHEADER - -// Copyright © nthState Ltd. ___YEAR___. All rights reserved. -// - - diff --git a/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/Package.swift b/Package.swift index 824a740..8802aad 100644 --- a/Package.swift +++ b/Package.swift @@ -1,24 +1,22 @@ -// swift-tools-version: 5.10 -// The swift-tools-version declares the minimum version of Swift required to build this package. +// swift-tools-version: 6.0 import PackageDescription let package = Package( name: "UUIDV7", - platforms: [.visionOS(.v1), .iOS(.v12)], products: [ - // Products define the executables and libraries a package produces, making them visible to other packages. .library( name: "UUIDV7", - targets: ["UUIDV7"]) + targets: ["UUIDV7"] + ) ], targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. .target( - name: "UUIDV7"), + name: "UUIDV7" + ), .testTarget( name: "UUIDV7Tests", - dependencies: ["UUIDV7"]) + dependencies: ["UUIDV7"] + ), ] ) diff --git a/Sources/UUIDV7/String+.swift b/Sources/UUIDV7/String+.swift index 40c4361..bb2bfe8 100644 --- a/Sources/UUIDV7/String+.swift +++ b/Sources/UUIDV7/String+.swift @@ -10,6 +10,10 @@ extension String { let regex = try? NSRegularExpression(pattern: pattern, options: []) let range = NSRange(location: 0, length: count) - return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1-$2-$3-$4-$5") ?? self + return regex?.stringByReplacingMatches( + in: self, + options: [], + range: range, withTemplate: "$1-$2-$3-$4-$5" + ) ?? self } } diff --git a/Sources/UUIDV7/UUIDV7.swift b/Sources/UUIDV7/UUIDV7.swift index f3b06ec..e3b4ad0 100644 --- a/Sources/UUIDV7/UUIDV7.swift +++ b/Sources/UUIDV7/UUIDV7.swift @@ -4,15 +4,15 @@ import Foundation -public extension UUID { +extension UUID { /// Generate a UUID Version 7 string /// - Parameter withHyphens: Format the string with hypens /// - Returns: A UUID Version 7 string - static func uuidV7String(withHyphens: Bool = true) -> String { + public static func uuidV7String(withHyphens: Bool = true) -> String { let timestamp = Date().timeIntervalSince1970 let unixTimeMilliseconds = UInt64(timestamp * 1000) - let timeBytes = unixTimeMilliseconds.bigEndianData.suffix(6) // First 6 bytes for the timestamp + let timeBytes = unixTimeMilliseconds.bigEndianData.suffix(6) // First 6 bytes for the timestamp // Prepare the random part (10 bytes to complete the UUID) let randomBytes = Data((0..<10).map { _ in UInt8.random(in: 0...255) }) diff --git a/Tests/UUIDV7Tests/UUIDV7Tests.swift b/Tests/UUIDV7Tests/UUIDV7Tests.swift index 5d8c92b..522ba0b 100644 --- a/Tests/UUIDV7Tests/UUIDV7Tests.swift +++ b/Tests/UUIDV7Tests/UUIDV7Tests.swift @@ -2,12 +2,14 @@ // Copyright © nthState Ltd. 2024. All rights reserved. // -@testable import UUIDV7 -import XCTest - -final class UUIDv7GeneratorTests: XCTestCase { - - func testGeneratedUUIDv7IsValidFormat() { +import Foundation +import Testing +import UUIDV7 + +@Suite +struct UUIDv7GeneratorTests { + @Test + func generatedUUIDv7IsValidFormat() { let uuid = UUID.uuidV7String() print("UUID: \(uuid)") @@ -18,28 +20,30 @@ final class UUIDv7GeneratorTests: XCTestCase { let range = NSRange(location: 0, length: uuid.count) let matches = regex?.numberOfMatches(in: uuid, options: [], range: range) - XCTAssertEqual(matches, 1, "Generated UUIDv7 should match the expected format") + #expect(matches == 1, "Generated UUIDv7 should match the expected format") } - func testGeneratedUUIDv7IsDifferentEachTime() { + @Test + func generatedUUIDv7IsDifferentEachTime() { let uuid1 = UUID.uuidV7String() let uuid2 = UUID.uuidV7String() print("UUID:1 \(uuid1)") print("UUID:2 \(uuid2)") - XCTAssertNotEqual(uuid1, uuid2, "Generated UUIDv7 should be different each time") + #expect(uuid1 != uuid2, "Generated UUIDv7 should be different each time") } - func testGeneratedUUIDv7IsLexicallyTimeSortable() { + @Test + func generatedUUIDv7IsLexicallyTimeSortable() async throws { let uuid1 = UUID.uuidV7String() - Thread.sleep(forTimeInterval: 0.05) // Wait for a few milliseconds + try await Task.sleep(nanoseconds: 5) // Wait for a few milliseconds let uuid2 = UUID.uuidV7String() print("UUID:1 \(uuid1)") print("UUID:2 \(uuid2)") // Directly compare the string representations - XCTAssertLessThan(uuid1, uuid2, "UUIDv7s should be lexically time-sortable") + #expect(uuid1 < uuid2, "UUIDv7s should be lexically time-sortable") } }