Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import AppDelegate.h file in Pod project ViewController?

I am new to the POD project. I want to update the pod project viewControllers,for that I need to access the AppDelegate class in Pod Project.

I have tried to update the Pod configuration file to access the AppDelegate but not able to get success.

like image 650
Swapnil1156035 Avatar asked Feb 11 '16 05:02

Swapnil1156035


1 Answers

You really don't want to create a circular dependency between your app and the pod. The recommended way to do this would be to define a protocol in the pod and make your AppDelegate implement that protocol.

@protocol PodArrayProvider
    - (NSArray *)arrayToAccess:
@end

// in AppDelegate.m
#import <Pod/Pod.h>

@extension AppDelegate () <PodArrayProvider>
@end

@implementation AppDelegate
- (NSArray *)arrayToAccess
{
    return self.realArray;
}
@end

// then in your pod, you can do:
id<PodArrayProvider> arrayProvider = (id<PodArrayProvider>)[[UIApplication sharedApplication] delegate];
NSAssert([arrayProvider conformsTo:@protocol(PodArrayProvider)], @"bad app delegate!");
NSArray *things = [arrayProvider arrayToAccess];

Something like the structure above should work, but I would urge you to rethink this architecture. The pod is a dependency of the app and shouldn't know anything about the app. The app should be telling the pod everything it needs to know.

like image 80
Dave Weston Avatar answered Sep 24 '22 11:09

Dave Weston