0

Current Situtation
I work on an iOS SDK containing several UIViewControllers that can be customized through a delegate function passing a String as the identifier and getting a customized CALayer. With that, the host application can customize how the SDK looks.

This is an example:

extension ViewController: NINChatSessionDelegate {
    func ninchat(_ session: NINChatSession, overrideLayer assetKey: CALayerConstant) -> CALayer? {
        switch assetKey {
        case .ninchatPrimaryButton:
            let layer = CALayer()
            layer.backgroundColor = UIColor.gray.cgColor
            layer.masksToBounds = true
            layer.cornerRadius = 20.0
            return layer
        default:
            return nil
    }
} 

Problem
Nowadays, I'm trying to migrate the code to SwiftUI and Combine. But I cannot find a way to offer host applications to inject their own attributes. As far as I have understood, a ViewModifier struct is used to apply custom attributes to one or multiple View(s) in SwiftUI. However, I could not yet find a way to inject them to the SDK because a ViewModifier protocol has Self or associated type requirements

I appreciate any helps and guides.

Hassan Shahbazi
  • 1,543
  • 9
  • 26
  • 1
    If i get your point correctly, it may be good to look and consider how `ButtonStyle` protocol works in SwiftUI itself. https://developer.apple.com/documentation/swiftui/buttonstyle – MrAlirezaa May 05 '21 at 14:38
  • @MrAlirezaa Thanks for the hint, but it doesn't answer my problem. The question is about _injecting_ custom configurations while all available protocols have some sort of **Self or associated type requirements** – Hassan Shahbazi May 06 '21 at 06:35

0 Answers0