Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Oct 22, 2023
1 parent d5e4a24 commit aecf063
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Sources/UpgradeAlert/UpgradeAlert+Variables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension UpgradeAlert {
* Default completion handler function.
* This function simply prints the outcome of the operation.
*/
public static let defaultComplete: Complete = { outcome in
public static let defaultComplete: Complete = { (outcome: UAOutcome) in
Swift.print("default complete - outcome: \(String(describing: outcome))")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/UpgradeAlert/UpgradeAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension UpgradeAlert {
public static func checkForUpdates(complete: Complete? = defaultComplete) { // complete: (_ appInfo: AppInfo?, error: NSError?)
// Perform network calls on a background thread
DispatchQueue.global(qos: .background).async {
getAppInfo { appInfo, error in
getAppInfo { (appInfo: AppInfo?, error: UAError?) in
// Fetch app information
guard let localVersion: String = Bundle.version, // Check if local version is available
error == nil // Check if there is no error
Expand Down
4 changes: 2 additions & 2 deletions Sources/UpgradeAlert/ext/Bundle+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ extension Bundle {
* fix. we could make BundleError enum BundleError: Error { case appStoreReceiptURLNotFound }
*/
public static var isBeta: Bool { // was named: isSimulatorOrTestFlight
guard let path = Bundle.main.appStoreReceiptURL?.path else {
guard let path: String = Bundle.main.appStoreReceiptURL?.path else {
Swift.print("isBeta - appStoreReceiptURL not found")
return false
}
let isSimulator: Bool = path.contains("CoreSimulator") // can also use #if !targetEnvironment(simulator) #else #endif here
let isSimulator: Bool = path.contains("CoreSimulator") // Can also use #if !targetEnvironment(simulator) #else #endif here
let isTestFlight: Bool = path.contains("sandboxReceipt")
return isSimulator || isTestFlight
}
Expand Down
1 change: 0 additions & 1 deletion Sources/UpgradeAlert/helper/LookupResult.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation

/**
* `LookupResult` is a struct that conforms to the `Decodable` protocol.
* It is used to parse the JSON response from the Apple App Store API.
Expand Down
4 changes: 2 additions & 2 deletions Sources/UpgradeAlert/helper/UAConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ extension UAConfig {
.init(
isRequired: false, // By default, upgrades are not mandatory.
alertTitle: "Update available", // Default alert title.
alertMessage: { appName, version in
if let appName = appName ?? Bundle.name {
alertMessage: { (appName: String?, version: String) in
if let appName: String = appName ?? Bundle.name {
// Default alert message when app name is available.
return "\(appName) Version \(version) is available on the AppStore."
} else {
Expand Down
21 changes: 17 additions & 4 deletions Sources/UpgradeAlert/helper/UAOutcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@ import Foundation
* - Fixme: ⚠️️ Add more detailed documentation for each case.
*/
public enum UAOutcome {
case updateNotNeeded // The app is up-to-date, no upgrade is needed.
case notNow // The user has chosen to defer the upgrade.
case didOpenAppStoreToUpdate // The user has opened the App Store to perform the upgrade.
case error(error: UAError) // An error occurred during the upgrade process.
/**
* Represents the outcome where the app is up-to-date and no upgrade is needed.
*/
case updateNotNeeded
/**
* Represents the outcome where the user has chosen to defer the upgrade.
*/
case notNow

Check warning on line 15 in Sources/UpgradeAlert/helper/UAOutcome.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
/**
* Represents the outcome where the user has opened the App Store to perform the upgrade.
*/
case didOpenAppStoreToUpdate

Check warning on line 19 in Sources/UpgradeAlert/helper/UAOutcome.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
/**
* Represents the outcome where an error occurred during the upgrade process.
* - Parameter error: The error that occurred during the upgrade process.
*/
case error(error: UAError)

Check warning on line 24 in Sources/UpgradeAlert/helper/UAOutcome.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
}
2 changes: 1 addition & 1 deletion Sources/UpgradeAlert/util/ComparisonResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension ComparisonResult {
* - appStore: "1.2.9" The version of the app in the App Store.
*/
static func compareVersion(current: String, appStore: String) -> ComparisonResult {
let versionCompare = current.compare(appStore, options: .numeric)
let versionCompare/*: ComparisonResult*/ = current.compare(appStore, options: .numeric)
switch versionCompare {
case .orderedSame:// The current version is the same as the App Store version.
//print("same version")
Expand Down
2 changes: 1 addition & 1 deletion Tests/UpgradeAlertTests/UpgradeAlertTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class UpgradeAlertTests: XCTestCase {
return
}
// Call the checkForUpdates function of the UpgradeAlert module and handle the outcome.
UpgradeAlert.checkForUpdates { outcome in
UpgradeAlert.checkForUpdates { (outcome: UAOutcome) in
if case .error(let err) = outcome {
Swift.print("Err: \(err.localizedDescription)")
} else {
Expand Down

0 comments on commit aecf063

Please sign in to comment.