I have case where I often scratch my head around, let's say I have a generic Manager
class in a pod that can handle permission, and within the app, I want to be able to extend it to create more meaningful method name, aka to use with enum as parameter, to make its use more clear and less prone to mistake.
But it seems that you can't call private method when you create the extension elsewhere.
I'm sure there would be a more clean way with Generic/AssociatedValue
or maybe my pattern is just wrong...
Here's the simplified version of it:
Class in the external pod:
public class FeatureDataManager {
public static let shared = FeatureDataManager()
private var permissionManager: PermissionManager!
private init() {
self.permissionManager = PermissionManager()
}
private getPermission(forFeature feature: String) -> Bool {
return self.permissionManager.isEnable(feature)
}
}
and the extension in the app:
extension FeatureDataManager {
enum FeatureType: String {
case ads = "ads"
case showBanner = "banner"
case showFullScreenPub = "showFullScreenPub"
}
public func isPermissionEnable(forFeature feature: FeatureType) {
// Does not compile, visibility issue
self.getPermission(forFeature: feature)
}
}
Aucun commentaire:
Enregistrer un commentaire