Swift 3 How to manage different delegates for different Targets

丶灬走出姿态 提交于 2019-12-12 03:39:36

问题


We have created two Targets (Target_One & Target_Two) for same project.

  • Target_One contain SDK1 and delegate Target1SDKHelperDelegate
  • Target_Two contain SDK2 and delegate Target2SDKHelperDelegate

The reason to create two target : we need to upload two apps with same UI but different SDK integration.

As we know, each SDK has their own delegates. So we want to apply delegates specific to the target.

Example: Target_One has a class named MyClass

class MyClass: NSObject, Target1SDKHelperDelegate {

}

In above class, we have implemented Target1SDKHelperDelegate delegate. We are using same class for Target_Two also and we want to use Target2SDKHelperDelegate for Target_Two.

So how we can put two different delegates to for two different targets?

We also know to manage target we should use below code.

#if Target_One

#else

#endif

But anyone tell us how to manage delegate by using above?

We want to do something like :

 class MyClass: NSObject
       #if Target_One
            , Target1SDKHelperDelegate 
      #else
            , Target2SDKHelperDelegate 
      #endif
   {

    }

回答1:


Can try like this code with use typealias:

#if FREE_VERSION
public typealias DELEGATES = UIViewController & AttributeUDBClientMainDelegate & AttributeSubscriptionHelperDelegate
#else
public typealias DELEGATES = UIViewController
#endif

public final class SettingsViewController: DELEGATES {



回答2:


Actually it is pretty simple and direct . Lately I faced the issue cause of size of iPA went too big like 20MB . I disabled not needed features from some targets and had to manage the shared files like Appdelegate when it has references to disabled features files . Solved this by simply duplicating Appdelegate file and put it in a specific paths related to specific targets . Then included each appDelegate file under its target. It worked . The idea is the same like if you have firebase push notifications pLists configuration files for multiple targets OR imageAssets folders. Hope this helps.



来源:https://stackoverflow.com/questions/41974346/swift-3-how-to-manage-different-delegates-for-different-targets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!