Skip to content

Commit

Permalink
Up to Swift6 and update logs #major
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Nov 3, 2024
1 parent 3dfecf0 commit 5fc903c
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
6 changes: 6 additions & 0 deletions Sources/OversizeCore/Extensions/Image/NSImage+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@
return bitmapRepresentation.representation(using: .jpeg, properties: [:])
}
}

public extension NSImage {
var cgImage: CGImage? {
cgImage(forProposedRect: nil, context: nil, hints: nil)
}
}
#endif
8 changes: 4 additions & 4 deletions Sources/OversizeCore/Extensions/Swift/Date+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ public extension Date {
}

extension Date: @retroactive RawRepresentable {
private static let formatter: ISO8601DateFormatter = .init()

public var rawValue: String {
Date.formatter.string(from: self)
let formatter = ISO8601DateFormatter()
return formatter.string(from: self)
}

public init?(rawValue: String) {
self = Date.formatter.date(from: rawValue) ?? Date()
let formatter = ISO8601DateFormatter()
self = formatter.date(from: rawValue) ?? Date()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ public extension Bool? {
}
return unwrapped
}

var valueOrTrue: Bool {
guard let unwrapped = self else {
return true
}
return unwrapped
}
}
13 changes: 13 additions & 0 deletions Sources/OversizeCore/Extensions/Swift/Sequence+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Copyright © 2024 Alexander Romanov
// Sequence+Extension.swift, created on 24.10.2024
//

import Foundation

public extension Sequence where Element: Hashable {
func removingDuplicates(by keyPath: KeyPath<Element, String>) -> [Element] {
var seen = Set<String>()
return filter { seen.insert($0[keyPath: keyPath]).inserted }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import Foundation

extension SortOrder: @retroactive CaseIterable, @retroactive Identifiable {
public static var allCases: [SortOrder] = [.forward, .reverse]
public static var allCases: [SortOrder] {
[.forward, .reverse]
}

public var title: String {
switch self {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OversizeCore/Global/Delay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

import Foundation

public func delay(time: TimeInterval, execute: @escaping () -> Void) {
public func delay(time: TimeInterval, execute: @Sendable @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + time, execute: execute)
}
84 changes: 83 additions & 1 deletion Sources/OversizeCore/Global/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,89 @@ public func log(_ object: Any?) {
public func logWithTime(_ text: String, terminator: String? = nil) {
#if DEBUG
let textTime: String = Date().formatted(.dateTime)
let textWithTime = "\(textTime): \(text)"
let textWithTime = "🕓 [\(textTime)] \(text)"
terminator == nil ? print(textWithTime) : print(textWithTime, terminator: terminator!)
#endif
}

@inlinable public func logDebug(_ text: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("⚪ [DEBUG] \(text)") : print("⚪ [DEBUG] \(text)", terminator: terminator!)
#endif
}

@inlinable public func logNotice(_ text: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("🛎️ [NOTICE] \(text)") : print("🛎️ [NOTICE] \(text)", terminator: terminator!)
#endif
}

@inlinable public func logInfo(_ text: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("ℹ️ [INFO] \(text)") : print("ℹ️ [INFO] \(text)", terminator: terminator!)
#endif
}

@_disfavoredOverload
@inlinable public func logSuccess(_ text: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("✅ [SUCCESS] \(text)") : print("✅ [SUCCESS] \(text)", terminator: terminator!)
#endif
}

public func logSuccess(_ text: String, object: Any?) {
#if DEBUG
print("✅ [SUCCESS] \(text), object:\n")
log(object)
#endif
}

@inlinable public func logWarning(_ text: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("⚠️ [WARNING] \(text)") : print("⚠️ [WARNING] \(text)", terminator: terminator!)
#endif
}

@inlinable public func logError(_ text: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("🔴 [ERROR] \(text)") : print("🔴 [ERROR] \(text)", terminator: terminator!)
#endif
}

@inlinable public func logError(_ text: String, error: Error, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("🔴 [ERROR] \(text):\n\(error.localizedDescription)") : print("🔴 [ERROR] \(text):\n\(error.localizedDescription)", terminator: terminator!)
#endif
}

@inlinable public func logError(_ text: String, error: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("🔴 [ERROR] \(text):\n\(error)") : print("🔴 [ERROR] \(text):\n\(error)", terminator: terminator!)
#endif
}

@inlinable public func logDeleted(_ text: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("🗑️ [DELETED] \(text)") : print("🗑️ [DELETED] \(text)", terminator: terminator!)
#endif
}

@inlinable public func logData(_ text: String, terminator: String? = nil) {
#if DEBUG
terminator == nil ? print("💽 [DATA] \(text)") : print("💽 [DATA] \(text)", terminator: terminator!)
#endif
}

@inlinable public func logUrl(_ text: String? = nil, url: URL?, terminator: String? = nil) {
#if DEBUG
guard let url else {
log("🔗 [URL] Nil or not valid URL", terminator: terminator)
return
}
if let text {
url.isFileURL ? log("📁 [URL] \(text):\n\(url.path)", terminator: terminator) : log("🌐 [URL] \(text):\n\(url.absoluteString)", terminator: terminator)
} else {
url.isFileURL ? log("📁 [URL] \(url.path)", terminator: terminator) : log("🌐 [URL] \(url.absoluteString)", terminator: terminator)
}
#endif
}

0 comments on commit 5fc903c

Please sign in to comment.