قالب وردپرس درنا توس
Home / IOS Development / lens c – iOS: circular dependence on call method in each other class

lens c – iOS: circular dependence on call method in each other class



I'm trying to implement circular dependency between appDelegate and my ViewController to call methods from appDelegate to my ViewController, but it doesn't work.

Here is my implementation appDelegate.h:

  @class ViewController;
@interface AppDelegate: UIResponder 
@property (strong, nonatomic) ViewController * mainView;

appDelegate.m:

  - (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {
return YES;
}

- (BOOL) application: (UIApplication *) app
openURL: (NSURL *) url
alternatives: (NSDictionary  *) options
{
[self.mainView doSomething];
return YES;
}

Here is my implementation on ViewController .h:

  #import 
@ class AppDelegate;

@interface ViewController: UIViewController
@property (strong, non-atomic) AppDelegate * delegate;

- (void) doSomething;

viewcontroller.m:

  - (void) viewDidLoad {
[super viewDidLoad];
self.delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
}

- (void) doSomething
{
NSLog (@ "doing something");
}

I have no errors or warnings, but the method does something. There has never been a ring. some of you know why or what am I doing wrong?

I really appreciate your help.


Source link