I got a one-year-old legacy project from other develop a team. In the project, I found a folder called "Utils". In this folder, There are many XxxxHelper.swift source code files. These helpers are also wrapping some third party pods.
Example: DeepLinkHelper wraps CocoaPods "Branch"
import Foundation
import Branch
class DeepLinkHelper {
static func handleDeepLink(params: [AnyHashable:Any]?, error: Error?) {
if error == nil {
if let clickedBranch = params?["+clicked_branch_link"] as? Bool, let referringLink = params?["~referring_link"] as? String, let referringUrl = referringLink.toURL(), clickedBranch {
let endpoint = referringUrl.lastPathComponent
switch(endpoint) {
case "debugLink":
#if ENV_DEBUG
NotificationCenter.default.post(name: Notification.Name(rawValue: InternalNotifications.backgroundAlertUser), object: nil, userInfo: ["title":"Branch Link","message":"Success!"])
#endif
break
case "connaccts":
// Display connected accounts
NotificationCenter.default.post(name: Notification.Name(rawValue:InternalNotifications.switchToViewController), object: nil, userInfo:["destination": ViewControllerNames.connections])
break
case "guestinvite":
// Request server to add source account as unvalidated connection
if let gValue = params?["g"] as? String {
handleGuestInvite(gValue)
}
break
default:
break
}
}
print("BranchIO-DLparams: \(String(describing:params))")
}
else {
print("BranchIO-Error: \(error!)")
}
}
static func handleGuestInvite(_ gValue: String) {
NotificationCenter.default.post(name: Notification.Name(rawValue:InternalNotifications.switchToViewController), object: nil, userInfo:["destination": ViewControllerNames.main,"reset":true,"guestInviteData":gValue])
}
}
Other helpers:
KeychainHelper.swift wraps the pod KeychainSwift. PhotoHelper.swift wraps the pod TOCropViewController and other native kits TrackingHelper.swift wraps the pod Tune
Question again:
What's these design pattern? And, what is the benefit to wrapping native or third-party SDKs and kits?
Aucun commentaire:
Enregistrer un commentaire