Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var package = Package(
path: "Source/TestFake"),
.target(
name: "SabyNetwork",
dependencies: ["SabyConcurrency", "SabyJSON", "SabySafe", "SabyTime"],
dependencies: ["SabyConcurrency", "SabyJSON", "SabyTime"],
path: "Source/Network"),
.target(
name: "SabyNumeric",
Expand Down
8 changes: 5 additions & 3 deletions Source/AppleFetcher/Implement/ScreenFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ public final class ScreenFetcher: Fetcher {
public typealias Value = Promise<Screen, Error>

public init() {}

public func fetch() -> Promise<Screen, Error> {
return Promise.all(
return Promise.tryAll(
Promise<CGSize, Error>.resolved(fetchSize()),
Promise<CGFloat, Error>.resolved(fetchScale()),
fetchOrientation()
)
.then { size, scale, orientation in
Screen(
let screen = Screen(
width: size.width,
height: size.height,
scale: scale,
orientation: orientation.isLandscape ? "landscape": "portrait"
)

return screen
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Source/AppleLogger/Data/LoggerSetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public struct LoggerSetting {
/// A variable indicating logger paginate log or not. Because of `os_log`'s 1024 length limit.
public var isPaginateLogEnabled: Bool = false

/// A variable indicating logger use legacy log system or not.
public var isLegacyLogEnabled: Bool = false

/// A variable used for displaying `subsystem` value in console
public let subsystem: String

Expand Down
28 changes: 17 additions & 11 deletions Source/AppleLogger/Implement/LogService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@ extension LogService {
_ message: String,
_ printBlock: (String) -> Void
) {
if setting.isPaginateLogEnabled, message.count > LoggerConstant.paginateSize {
let logs = LoggerConstant.paginatedLog(message)
let id = arc4random() % 1000000000

logs.enumerated().forEach { (index, log) in
printBlock(
"\(log)"
+ "\nlog={page=\(index + 1)/\(logs.count), id=\(id)}"
)
}
let header = setting.isLegacyLogEnabled
? "[\(setting.subsystem)][\(setting.category)]\n"
: ""

guard setting.isPaginateLogEnabled, message.count > LoggerConstant.paginateSize
else {
printBlock(header + message)
return
}

printBlock(message)
let logs = LoggerConstant.paginatedLog(message)
let id = arc4random() % 1000000000
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

레거시 난수 함수를 Swift의 현대적 API로 교체하세요.

arc4random() % 1000000000 대신 Swift의 Int.random(in:) API를 사용하는 것이 권장됩니다. 이는 더 안전하고 Swift의 표준 관행에 부합합니다.

다음과 같이 수정하세요:

-        let id = arc4random() % 1000000000
+        let id = Int.random(in: 0..<1000000000)

Based on static analysis hints from SwiftLint.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let id = arc4random() % 1000000000
let id = Int.random(in: 0..<1000000000)
🧰 Tools
🪛 SwiftLint (0.57.0)

[Warning] 32-32: Prefer using type.random(in:) over legacy functions

(legacy_random)

🤖 Prompt for AI Agents
In Source/AppleLogger/Implement/LogService.swift around line 32, replace the
legacy C-style random generation "let id = arc4random() % 1000000000" with
Swift's modern API by assigning id using Int.random(in: 0..<1_000_000_000); this
removes arc4random usage, matches SwiftLint guidance, and preserves the same
range and integer type.


logs
.enumerated()
.map { (index, log) in
let footer = "\nlog={page=\(index + 1)/\(logs.count), id=\(id)}"
return header + log + footer
}
.forEach(printBlock)
}
}

Expand Down
1 change: 0 additions & 1 deletion Source/ApplePreference/Implement/FileValuePreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SabySafe
import SabyConcurrency
import SabyJSON

Expand Down
1 change: 0 additions & 1 deletion Source/AppleStorage/Implement/CoreDataArrayStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import CoreData

import SabyConcurrency
import SabySafe
import SabySize
import SabyJSON

Expand Down
1 change: 0 additions & 1 deletion Source/AppleStorage/Implement/FileValueStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import SabySafe
import SabyConcurrency
import SabyJSON

Expand Down
1 change: 0 additions & 1 deletion Source/Network/Implement/Client/JSONClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation

import SabyConcurrency
import SabySafe
import SabyJSON
import SabyTime

Expand Down