How to add a framework inside another framework (Umbrella Framework)

后端 未结 4 1971
旧时难觅i
旧时难觅i 2020-12-02 09:52

I have build a framework using the following tutorial.

And I also got this framework.

I am trying to implement the second Framework inside mine, from what I re

4条回答
  •  难免孤独
    2020-12-02 10:23

    Apple discourages you to create an umbrella framework but yet, still says it is possible with some description on its structure etc' so i'll focus on how to actually do it.

    I must mention that if you control one or more frameworks, bundling them into one is not such a bad idea and can help the end-developer.

    Creating an umbrella framework is really simple now on recent Xcodes (7 and up)

    Here's how to do it.

    First create a framework:

    Drag CrashReporter.framework to the Umbrella framework project:

    Example code to make sure both frameworks are functional:

    Umbrella.h:

    #import 
    #import 
    
    @interface Umbrella : NSObject
    
    +(void)sayHelloFromUmbrella;
    
    @end
    

    Umbrella.m:

    #import "Umbrella.h"
    #import 
    
    @implementation Umbrella
    
    +(void)sayHelloFromUmbrella
    {
        NSLog(@"Hey from Umbrella");
        PLCrashReporter *crashObject = [[PLCrashReporter alloc]initWithConfiguration:nil];
        NSLog(@"crashObject: %@",crashObject);
    }
    
    @end
    

    Build and you'll get the Umbrella.framework (that contains CrashReporter.framework) in your build folder.

    Drag Umbrella.framework and place it inside "Embedded Binaries" in the project that is going to use it:

    Then just import your finished framework.

    ViewController.m from the project that we just dragged Umbrella.framework to:

    #import "ViewController.h"
    #import 
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        [Umbrella sayHelloFromUmbrella];
    }
    

    Which will output this:

    Hey from Umbrella 
    crashObject: 
    

    Which tells us that both frameworks are working.

提交回复
热议问题