diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Formbricks.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Formbricks.swift index f90d519142..25ca22d67d 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Formbricks.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Formbricks.swift @@ -14,7 +14,13 @@ import Network static internal var service = FormbricksService() // make this class not instantiatable outside of the SDK - internal override init() {} + internal override init() { + /* + This empty initializer prevents external instantiation of the Formbricks class. + All methods are static and the class serves as a namespace for the SDK, + so instance creation is not needed and should be restricted. + */ + } /** Initializes the Formbricks SDK with the given config ``FormbricksConfig``. diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyCodable.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyCodable.swift index d8e0b7e4d5..28e949ccf9 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyCodable.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyCodable.swift @@ -22,7 +22,7 @@ struct AnyCodable: Codable { } } -extension AnyCodable: _AnyEncodable, _AnyDecodable {} +extension AnyCodable: AnyEncodableProtocol, AnyDecodableProtocol {} extension AnyCodable: Equatable { public static func == (lhs: AnyCodable, rhs: AnyCodable) -> Bool { @@ -88,12 +88,10 @@ extension AnyCodable: CustomStringConvertible { extension AnyCodable: CustomDebugStringConvertible { public var debugDescription: String { - switch value { - case let value as CustomDebugStringConvertible: + if let value = value as? CustomDebugStringConvertible { return "AnyCodable(\(value.debugDescription))" - default: - return "AnyCodable(\(description))" } + return "AnyCodable(\(description))" } } diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyDecodable.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyDecodable.swift index 198798dedb..9941c869f4 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyDecodable.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyDecodable.swift @@ -42,14 +42,14 @@ struct AnyDecodable: Decodable { } @usableFromInline -protocol _AnyDecodable { +protocol AnyDecodableProtocol { var value: Any { get } init(_ value: T?) } -extension AnyDecodable: _AnyDecodable {} +extension AnyDecodable: AnyDecodableProtocol {} -extension _AnyDecodable { +extension AnyDecodableProtocol { public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() @@ -139,10 +139,9 @@ extension AnyDecodable: CustomStringConvertible { extension AnyDecodable: CustomDebugStringConvertible { public var debugDescription: String { - switch value { - case let value as CustomDebugStringConvertible: + if let value = value as? CustomDebugStringConvertible { return "AnyDecodable(\(value.debugDescription))" - default: + } else { return "AnyDecodable(\(description))" } } diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyEncodable.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyEncodable.swift index 6a2d4e5ae2..f891fec484 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyEncodable.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Helpers/AnyCodable/AnyEncodable.swift @@ -40,16 +40,16 @@ struct AnyEncodable: Encodable { } @usableFromInline -protocol _AnyEncodable { +protocol AnyEncodableProtocol { var value: Any { get } init(_ value: T?) } -extension AnyEncodable: _AnyEncodable {} +extension AnyEncodable: AnyEncodableProtocol {} // MARK: - Encodable -extension _AnyEncodable { +extension AnyEncodableProtocol { public func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() @@ -199,10 +199,9 @@ extension AnyEncodable: CustomStringConvertible { extension AnyEncodable: CustomDebugStringConvertible { public var debugDescription: String { - switch value { - case let value as CustomDebugStringConvertible: + if let value = value as? CustomDebugStringConvertible { return "AnyEncodable(\(value.debugDescription))" - default: + } else { return "AnyEncodable(\(description))" } } @@ -217,7 +216,7 @@ extension AnyEncodable: ExpressibleByStringInterpolation {} extension AnyEncodable: ExpressibleByArrayLiteral {} extension AnyEncodable: ExpressibleByDictionaryLiteral {} -extension _AnyEncodable { +extension AnyEncodableProtocol { public init(nilLiteral _: ()) { self.init(nil as Any?) } diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Manager/PresentSurveyManager.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Manager/PresentSurveyManager.swift index 10dabbafc9..815cc16e77 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Manager/PresentSurveyManager.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Manager/PresentSurveyManager.swift @@ -3,7 +3,12 @@ import SwiftUI /// Presents a survey webview to the window's root final class PresentSurveyManager { static let shared = PresentSurveyManager() - private init() { } + private init() { + /* + This empty initializer prevents external instantiation of the PresentSurveyManager class. + The class serves as a namespace for the present method, so instance creation is not needed and should be restricted. + */ + } /// The view controller that will present the survey window. private weak var viewController: UIViewController? @@ -29,6 +34,4 @@ final class PresentSurveyManager { func dismissView() { viewController?.dismiss(animated: true) } - - } diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Manager/SurveyManager.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Manager/SurveyManager.swift index 340d48bf2c..1d1ae40282 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Manager/SurveyManager.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Manager/SurveyManager.swift @@ -4,7 +4,12 @@ import SwiftUI /// Filtering surveys based on the user's segments, responses, and displays. final class SurveyManager { static let shared = SurveyManager() - private init() { } + private init() { + /* + This empty initializer prevents external instantiation of the SurveyManager class. + The class serves as a namespace for the shared instance, so instance creation is not needed and should be restricted. + */ + } private static let environmentResponseObjectKey = "environmentResponseObjectKey" internal var service = FormbricksService() @@ -124,7 +129,7 @@ private extension SurveyManager { if let environmentResponse = environmentResponse { PresentSurveyManager.shared.present(environmentResponse: environmentResponse, id: id) } - + } /// Starts a timer to refresh the environment state after the given timeout (`expiresAt`). @@ -200,7 +205,9 @@ private extension SurveyManager { case .displaySome: if let limit = survey.displayLimit { - if responses.contains(where: { $0 == survey.id }) { return false } + if responses.contains(where: { $0 == survey.id }) { + return false + } return displays.filter { $0.surveyId == survey.id }.count < limit } else { return true @@ -236,5 +243,5 @@ private extension SurveyManager { return segments.contains(segmentId) } } - + } diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Manager/UserManager.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Manager/UserManager.swift index 77c69f0535..431885243f 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Manager/UserManager.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Manager/UserManager.swift @@ -3,7 +3,12 @@ import Foundation /// Store and manage user state and sync with the server when needed. final class UserManager { static let shared = UserManager() - private init() { } + private init() { + /* + This empty initializer prevents external instantiation of the UserManager class. + The class serves as a namespace for the user state, so instance creation is not needed and should be restricted. + */ + } private static let userIdKey = "userIdKey" private static let contactIdKey = "contactIdKey" diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Networking/Base/APIClient.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Networking/Base/APIClient.swift index 8d9dc3e8c9..ef6a68c7b4 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Networking/Base/APIClient.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Networking/Base/APIClient.swift @@ -54,8 +54,7 @@ class APIClient: Operation, @unchecked Sendable { responseLogMessage.append(urlString) } - switch httpStatus.responseType { - case .success: + if httpStatus.responseType == .success { guard let data = data else { self.completion?(.failure(FormbricksAPIClientError(type: .invalidResponse, statusCode: httpStatus.rawValue))) return @@ -73,12 +72,12 @@ class APIClient: Operation, @unchecked Sendable { Formbricks.logger.info(responseLogMessage) // We want to save the entire response dictionary for the environment response - if var environmentResponse = body as? EnvironmentResponse { - if let jsonString = String(data: data, encoding: .utf8) { - environmentResponse.responseString = jsonString - body = environmentResponse as! Request.Response - } + if var environmentResponse = body as? EnvironmentResponse, + let jsonString = String(data: data, encoding: .utf8) { + environmentResponse.responseString = jsonString + body = environmentResponse as! Request.Response } + self.completion?(.success(body)) } @@ -111,8 +110,7 @@ class APIClient: Operation, @unchecked Sendable { Formbricks.logger.error(responseLogMessage) self.completion?(.failure(FormbricksAPIClientError(type: .invalidResponse, statusCode: httpStatus.rawValue))) } - - default: + } else { if let error = error { responseLogMessage.append("\nError: \(error.localizedDescription)") Formbricks.logger.error(responseLogMessage) diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/Networking/Base/HTTPStatusCode.swift b/packages/ios/FormbricksSDK/FormbricksSDK/Networking/Base/HTTPStatusCode.swift index a72adf9975..eca00f918f 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/Networking/Base/HTTPStatusCode.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/Networking/Base/HTTPStatusCode.swift @@ -20,7 +20,7 @@ enum HTTPStatusCode: Int, Error { // MARK: - Informational - 1xx - /// - continue: The server has received the request headers and the client should proceed to send the request body. - case `continue` = 100 + case httpContinue = 100 /// - switchingProtocols: The requester has asked the server to switch protocols and the server has agreed to do so. case switchingProtocols = 101 diff --git a/packages/ios/FormbricksSDK/FormbricksSDK/WebView/SurveyWebView.swift b/packages/ios/FormbricksSDK/FormbricksSDK/WebView/SurveyWebView.swift index e5297c8fdb..16a420d9a6 100644 --- a/packages/ios/FormbricksSDK/FormbricksSDK/WebView/SurveyWebView.swift +++ b/packages/ios/FormbricksSDK/FormbricksSDK/WebView/SurveyWebView.swift @@ -45,7 +45,13 @@ struct SurveyWebView: UIViewRepresentable { HTTPCookieStorage.shared.removeCookies(since: Date.distantPast) WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in records.forEach { record in - WKWebsiteDataStore.default().removeData(ofTypes: record.dataTypes, for: [record], completionHandler: {}) + WKWebsiteDataStore.default().removeData(ofTypes: record.dataTypes, for: [record], completionHandler: { + /* + This completion handler is intentionally empty since we only need to + ensure the data is removed. No additional actions are required after + the website data has been cleared. + */ + }) } } } @@ -56,7 +62,13 @@ extension SurveyWebView { // webView function handles Javascipt alert func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) { let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert) - alertController.addAction(UIAlertAction(title: "OK", style: .default) { _ in }) + alertController.addAction(UIAlertAction(title: "OK", style: .default) { _ in + /* + This closure is intentionally empty since we only need a simple OK button + to dismiss the alert. The alert dismissal is handled automatically by the + system when the button is tapped. + */ + }) UIApplication.safeKeyWindow?.rootViewController?.presentedViewController?.present(alertController, animated: true) completionHandler() }