Skip to content

Commit 79eeed0

Browse files
committed
Improve description comments with gpt4
1 parent 1de1a6a commit 79eeed0

14 files changed

+68
-17
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ UpgradeAlert.showAlert(appInfo: .init(version: "1.0.1", trackViewUrl: "https://a
9696
- Maybe add 1 day delay to showing update alert: to avoid an issue where Apple updates the JSON faster than the app binary propogates to the App Store. https://github.com/amebalabs/AppVersion/blob/master/AppVersion/Source/%20Extensions/Date%2BAppVersion.swift
9797
- Doc params
9898
- Clean up comments
99+
- Add support for swiftui
99100

100101
## License
101102
This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file.

Sources/UpgradeAlert/UpgradeAlert+Variables.swift

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extension UpgradeAlert {
66
/**
77
* Computed property to generate the request URL for app information.
88
* It uses the bundle identifier of the current app to create the URL.
9+
* - Description: This property constructs a URL used to fetch information about the application from the iTunes API based on the application's bundle identifier.
910
* - Returns: A URL pointing to the app's information on iTunes.
1011
* - Note: This URL might need a country code for region-specific apps.
1112
* - Fixme: ⚠️️ Consider renaming this to appInfoRequestURL for clarity.
@@ -23,6 +24,7 @@ extension UpgradeAlert {
2324
extension UpgradeAlert {
2425
/**
2526
* Typealias for a function that generates an alert message.
27+
* - Description: Defines a function type used to generate a custom alert message based on the app's name and version.
2628
* - Parameters:
2729
* - appName: The name of the app. This can be nil.
2830
* - version: The version of the app.
@@ -32,6 +34,7 @@ extension UpgradeAlert {
3234
public typealias AlertMessage = (_ appName: String?, _ version: String) -> String
3335
/**
3436
* Typealias for a completion handler function.
37+
* - Description: Defines a closure used as a completion handler to process the outcome of an update check or alert interaction.
3538
* - Parameters:
3639
* - outcome: The outcome of the operation, encapsulated in a UAOutcome object.
3740
* - Note: This function does not return a value.
@@ -40,6 +43,7 @@ extension UpgradeAlert {
4043
/**
4144
* Default completion handler function.
4245
* This function simply prints the outcome of the operation.
46+
* - Description: This default completion handler logs the outcome of the operation to the console, providing a simple way to observe the results of the update check or alert interaction.
4347
*/
4448
public static let defaultComplete: Complete = { (outcome: UAOutcome) in
4549
Swift.print("default complete - outcome: \(String(describing: outcome))")
@@ -51,6 +55,7 @@ extension UpgradeAlert {
5155
extension UpgradeAlert {
5256
/**
5357
* Static property to hold the configuration for UpgradeAlert.
58+
* - Description: Holds the configuration settings for the UpgradeAlert system, which can be customized as needed.
5459
* - Note: By default, it uses the default configuration defined in UAConfig.
5560
*/
5661
public static var config: UAConfig = .defaultConfig

Sources/UpgradeAlert/UpgradeAlert.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import UIKit
55
import Cocoa
66
#endif
77
/**
8+
* - Description: The `UpgradeAlert` class is responsible for managing the update notification process within an application. It checks for new versions of the app on the App Store, compares it with the current version, and alerts the user if an update is necessary.
89
* - Remark: What if a user doesn't want to update and there is no other option than to update?
910
* - Remark: If the app always show popup when getting focus. Then activate flight-mode. Launch the app again.
1011
* - Remark: Title and message are optional, default values are used if nil etc
@@ -17,6 +18,7 @@ public final class UpgradeAlert {}
1718
extension UpgradeAlert {
1819
/**
1920
* Check for updates
21+
* - Description: Initiates a check for new versions of the app available on the App Store. If a newer version is found, it prompts the user with an update alert.
2022
* - Remark: shows alert with one or two btns
2123
* - Parameter: withConfirmation You can force the update by calling, Or the user can choose if they want to update now or later by calling
2224
* - Remark: Version of the app you want to mark for the update. For example, 1.0.0 // This is the version you want the user to force upgrade to a newer version.
@@ -61,6 +63,7 @@ extension UpgradeAlert {
6163
*/
6264
extension UpgradeAlert {
6365
/**
66+
* - Description: Retrieves the app information from the App Store using a network request. This function fetches the JSON data from the App Store API and decodes it to `AppInfo` format, handling errors appropriately.
6467
* let url = URL(string: "http://www.")
6568
* - Remark: The url will work if the app is available for all markets. but if the app is removed from some countries. the url wont work. language code must be added etc: see: https://medium.com/usemobile/get-app-version-from-app-store-and-more-e43c5055156a
6669
* - Note: More url and json parsing here: https://github.com/appupgrade-dev/app-upgrade-ios-sdk/blob/main/Sources/AppUpgrade/AppUpgradeApi.swift
@@ -95,13 +98,13 @@ extension UpgradeAlert {
9598
task.resume()
9699
}
97100
}
98-
99101
/**
100102
* Alert
101103
*/
102104
extension UpgradeAlert {
103105
/**
104106
* Example code for iOS: mark with os fence
107+
* - Description: Presents an alert to the user with options based on the app's update requirements. The alert informs the user about the availability of a new version and provides options to update immediately or defer the update.
105108
* - Remark: For macOS it coud be wise to add some comment regarding setting system-wide autoupdate to avoid future alert popups etc
106109
* - Remark: Can be used: "itms-apps://itunes.apple.com/app/\(appId)")
107110
* - Remark: "itms-apps://itunes.apple.com/app/apple-store/id375380948?mt=8"

Sources/UpgradeAlert/ext/Bundle+Ext.swift

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@ import Foundation
55
extension Bundle {
66
/**
77
* The name of the main bundle.
8+
* - Description: Retrieves the name of the main bundle of the application.
9+
* Example: `let appName = Bundle.name`
810
*/
911
internal static let name: String? = Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String
1012
/**
1113
* The version of the main bundle.
14+
* - Description: Retrieves the version number of the main bundle of the application.
15+
* Example: `let appVersion = Bundle.version`
1216
*/
1317
internal static let version: String? = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
1418
/**
1519
* The build number of the main bundle.
20+
* - Description: Retrieves the build number of the main bundle of the application.
21+
* Example: `let buildNumber = Bundle.build`
1622
*/
1723
internal static let build: String? = Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
1824
/**
1925
* The identifier of the main bundle.
26+
* - Description: Retrieves the unique identifier of the main bundle of the application.
27+
* Example: `let bundleIdentifier = Bundle.identifier`
2028
*/
2129
internal static let identifier: String? = Bundle.main.object(forInfoDictionaryKey: kCFBundleIdentifierKey as String) as? String
2230
/**
2331
* Tests if an app is in beta
24-
* Description: determines if beta from receipt
32+
* - Abstract: determines if beta from receipt
33+
* - Description: Determines if the application is a beta version by checking the app store receipt URL for specific substrings that identify simulator or TestFlight environments.
2534
* - Note: From here: https://stackoverflow.com/a/38984554/5389500
2635
* - Note: More complex example: https://stackoverflow.com/a/33830605/5389500
2736
* - Note: Another example: https://stackoverflow.com/a/59047187/5389500
@@ -30,13 +39,17 @@ extension Bundle {
3039
* - Note: Seems like this can determine if an app is beta: https://developer.apple.com/documentation/appstoreconnectapi/list_all_builds_of_an_app
3140
* - Fixme: ⚠️️ Here is code that checks if something is testflight: https://gist.github.com/lukaskubanek/cbfcab29c0c93e0e9e0a16ab09586996
3241
* fix. we could make BundleError enum BundleError: Error { case appStoreReceiptURLNotFound }
42+
* Example: `let isBeta = Bundle.isBeta`
3343
*/
3444
public static var isBeta: Bool { // was named: isSimulatorOrTestFlight
45+
// Retrieves the path of the app store receipt URL, if it exists.
3546
guard let path: String = Bundle.main.appStoreReceiptURL?.path else {
3647
Swift.print("isBeta - appStoreReceiptURL not found")
3748
return false
3849
}
50+
// Determines if the application is running in a simulator environment by checking for "CoreSimulator" in the app store receipt URL path.
3951
let isSimulator: Bool = path.contains("CoreSimulator") // Can also use #if !targetEnvironment(simulator) #else #endif here
52+
// Determines if the app is distributed via TestFlight by checking for "sandboxReceipt" in the app store receipt URL path.
4053
let isTestFlight: Bool = path.contains("sandboxReceipt")
4154
return isSimulator || isTestFlight
4255
}

Sources/UpgradeAlert/ext/NSAlert+Ext.swift

+5-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Cocoa
44
extension NSAlert {
55
/**
66
* Presents a warning alert to the user with customizable text, buttons, and completion handler.
7-
*
7+
* - Description: Displays a modal alert dialog on macOS with customizable titles for the buttons and a completion handler to capture the user's response.
88
* ## Examples:
99
* NSAlert.present(question: "Ok?", text: "Choose your answer.") { answer in
1010
* print(answer)
@@ -19,10 +19,10 @@ extension NSAlert {
1919
* - complete: A closure that is called when the user dismisses the alert. The closure takes a single Boolean parameter that is true if the user clicked the OK button and false otherwise.
2020
*/
2121
internal static func present(question: String, text: String, okTitle: String? = "OK", cancelTitle: String? = "Cancel", view: NSView? = nil, complete: ((_ answer: Bool) -> Void)?) {
22-
let alert: NSAlert = .init()
23-
alert.messageText = question
24-
alert.informativeText = text
25-
alert.alertStyle = .warning
22+
let alert: NSAlert = .init() // Initializes a new NSAlert object.
23+
alert.messageText = question // Sets the primary message text of the alert.
24+
alert.informativeText = text // Sets the secondary, informative text of the alert.
25+
alert.alertStyle = .warning // Sets the alert style to warning, indicating the nature of the alert.
2626
// Add OK button to the alert
2727
if let okTitle: String = okTitle { alert.addButton(withTitle: okTitle) }
2828
// Add Cancel button to the alert
@@ -43,7 +43,3 @@ extension NSAlert {
4343
}
4444
}
4545
#endif
46-
//if anAlert.runModal() == .alertFirstButtonReturn {
47-
// return .terminateNow
48-
//}
49-
//return .terminateLater

Sources/UpgradeAlert/ext/UIAlertController+Ext.swift

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import UIKit
44
extension UIAlertController {
55
/**
66
* Present alert
7+
* - Description: Presents the alert controller modally on the currently active view controller or the root view controller if no other controllers are presented.
78
* Fix: throw error if vc is not available?
89
*/
910
internal func present() {
@@ -16,6 +17,7 @@ extension UIAlertController {
1617
extension UIAlertController {
1718
/**
1819
* Presented or root view-controller
20+
* - Description: Retrieves the currently presented view controller or the root view controller if no other view controller is presented.
1921
* - Note: Sometimes there is no vc: https://stackoverflow.com/a/30509569/5389500
2022
*/
2123
fileprivate static var presentedOrRootVC: UIViewController? {

Sources/UpgradeAlert/ext/UIApplication+Ext.swift

+2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import UIKit
66
extension UIApplication {
77
/**
88
* Key window property.
9+
* - Description: Retrieves the primary window of the application that is currently receiving user events.
910
* - Remark: The key scene can be found by accessing `keyWin.windowScene`.
1011
* - Returns: The key window if it exists, otherwise nil.
1112
*/
1213
internal var keyWin: UIWindow? {
1314
self
15+
// Retrieves all connected scenes of the application.
1416
.connectedScenes
1517
// Flatten the array of windows from each UIWindowScene
1618
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }

Sources/UpgradeAlert/helper/AppInfo.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@ import Foundation
33
/**
44
* This struct represents the basic information about an application.
55
* It includes the current version of the application and the URL to the application's page on the App Store.
6-
*
6+
* - Description: This struct encapsulates essential details about the application, such as its current version and the URL to its App Store page, facilitating easy access to its public listing for update and review purposes.
77
* - Remark: More information such as rating, release date, release notes etc. can be fetched. For more details, see: https://github.com/amebalabs/AppVersion/blob/master/AppVersion/Source/AppStoreVersion.swift
88
* - Fixme: ⚠️️ Consider renaming this struct to UAAppInfo for better clarity.
99
* - Fixme: ⚠️️ Add more detailed documentation for this struct and its properties.
1010
*/
1111
public struct AppInfo: Decodable {
1212
/**
1313
* The current version of the application.
14+
* - Description: Specifies the version of the application as a string, which is used to determine if an update is needed.
1415
*/
1516
public let version: String
1617
/**
1718
* The URL to the application's page on the App Store.
1819
* This might be optional for macOS applications as they might not have an App Store page.
20+
* - Description: Specifies the URL to the application's page on the App Store, which can be used to direct users to update or review the app.
1921
*/
2022
public let trackViewUrl: String
2123
/**
2224
* Initializes a new instance of `AppInfo`.
25+
* - Description: Initializes a new instance of `AppInfo` with the specified version and App Store URL.
2326
* - Parameters:
2427
* - version: The current version of the application.
2528
* - trackViewUrl: The URL to the application's page on the App Store.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import Foundation
22
/**
33
* `LookupResult` is a struct that conforms to the `Decodable` protocol.
4+
* - Description: Represents the result of a lookup operation in the Apple App Store API, encapsulating the relevant app information fetched.
45
* It is used to parse the JSON response from the Apple App Store API.
56
* The parsed data is stored in the `results` array, which contains instances of `AppInfo`.
6-
*
77
* - Note: This struct is part of the `UpgradeAlert` module, specifically under the `helper` directory.
88
*/
99
struct LookupResult: Decodable {
1010
// `results` is an array of `AppInfo` instances.
1111
// Each `AppInfo` instance represents the information of an app retrieved from the Apple App Store API.
12+
// Description: An array holding the app information fetched from the Apple App Store API.
1213
let results: [AppInfo]
1314
}

Sources/UpgradeAlert/helper/UAConfig.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,37 @@ import Foundation
22
/**
33
* This struct is used to configure the Upgrade Alert (UA).
44
* It contains all the necessary parameters to customize the alert message.
5+
* - Description: This struct configures the behavior and presentation of upgrade alerts within the application, allowing customization of alert titles, messages, and button labels based on the upgrade requirements.
56
*/
67
public struct UAConfig {
78
/**
89
* Determines whether the upgrade is mandatory or optional.
10+
* - Description: Indicates if the update is compulsory, requiring immediate action, or if it can be deferred.
911
*/
1012
let isRequired: Bool
1113
/**
1214
* The title of the alert.
15+
* - Description: The title displayed on the upgrade alert, informing the user of the nature of the alert.
1316
*/
1417
let alertTitle: String
1518
/**
1619
* The message of the alert. It's a function that takes the app name and version as parameters.
20+
* - Description: Specifies the content of the alert message, dynamically generated based on the application's name and the new version available.
1721
*/
1822
let alertMessage: UpgradeAlert.AlertMessage
1923
/**
2024
* The title of the button that allows the user to postpone the upgrade.
25+
* - Description: The title of the button that allows the user to defer the upgrade process, providing an option to initiate it at a later time.
2126
*/
2227
let laterButtonTitle: String
2328
/**
2429
* The title of the button that initiates the upgrade.
30+
* - Description: The title of the button that initiates the upgrade process, prompting the user to immediately download and install the latest version of the application.
2531
*/
2632
let updateButtonTitle: String
2733
/**
2834
* Initializes a new UAConfig with the given parameters.
29-
*
35+
* - Description: Initializes a new instance of `UAConfig` with specified settings for the upgrade alert.
3036
* - Parameters:
3137
* - isRequired: A boolean indicating whether the upgrade is mandatory.
3238
* - alertTitle: The title of the alert.
@@ -49,6 +55,7 @@ extension UAConfig {
4955
/**
5056
* Provides a default configuration for the alert.
5157
* This can be used when no specific configuration is provided.
58+
* - Description: Returns a default `UAConfig` instance with predefined values for alert title, message, and button titles, suitable for general use cases where a specific configuration is not necessary.
5259
*/
5360
public static let defaultConfig: UAConfig = {
5461
.init(

Sources/UpgradeAlert/helper/UAError.swift

+5
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@ import Foundation
22
/**
33
* Error type. So we can track if bundle id etc faults.
44
* This enum is used to handle errors in a more structured way, allowing for better error handling and debugging.
5+
* - Description: Enumerates the various errors that can occur within the UpgradeAlert system, providing specific types for different error scenarios to facilitate precise error handling.
56
*/
67
public enum UAError: Error {
78
/**
89
* This error is thrown when the URL for the App Store is invalid.
10+
* - Description: Occurs when the URL intended to direct to the App Store is malformed or not properly formatted, preventing navigation to the App Store page.
911
*/
1012
case invalidAppStoreURL
1113
/**
1214
* This error is thrown when a general URL is invalid.
15+
* - Description: Occurs when a general URL that is not specifically for the App Store is malformed or not properly formatted, preventing proper URL navigation or usage.
1316
*/
1417
case invalideURL
1518
/**
1619
* This error is thrown when the response from a request is invalid.
1720
* - Parameter description: Provides more details about the error.
21+
* - Description: Provides a detailed explanation of what went wrong with the response, including specifics that can help in debugging the issue.
1822
*/
1923
case invalidResponse(description: String)
2024
/**
2125
* This error is thrown when there is an issue with the bundle.
2226
* The desc parameter provides more details about the error.
27+
* - Description: Indicates an error related to the application's bundle, such as missing required resources or incorrect configuration settings.
2328
*/
2429
case bundleErr(desc: String)
2530
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
import Foundation
22
/**
33
* This enum represents the possible outcomes of an upgrade alert.
4+
* - Description: Enumerates the various outcomes that can occur after presenting an upgrade alert to the user, allowing for a structured response handling based on the user's decision or any error that might occur.
45
* - Fixme: ⚠️️ Consider renaming the cases to: notNow, notNeeded, appStoreOpened for better clarity.
56
* - Fixme: ⚠️️ Add more detailed documentation for each case.
67
*/
78
public enum UAOutcome {
89
/**
910
* Represents the outcome where the app is up-to-date and no upgrade is needed.
11+
* - Description: Indicates that the current version of the application is the latest available version, and no update action is required.
1012
*/
1113
case updateNotNeeded
1214
/**
1315
* Represents the outcome where the user has chosen to defer the upgrade.
16+
* - Description: Indicates that the user has chosen to delay the upgrade process, opting to not update the application at this time.
1417
*/
1518
case notNow
1619
/**
1720
* Represents the outcome where the user has opened the App Store to perform the upgrade.
21+
* - Description: Indicates that the user has initiated the upgrade process by opening the App Store to download the latest version of the application.
1822
*/
1923
case didOpenAppStoreToUpdate
2024
/**
2125
* Represents the outcome where an error occurred during the upgrade process.
2226
* - Parameter error: The error that occurred during the upgrade process.
27+
* - Description: Provides details about the specific error that prevented the upgrade process from completing successfully.
2328
*/
2429
case error(error: UAError)
2530
}

0 commit comments

Comments
 (0)