Delegate delegate delegate appdelegate

    MyAppDelegate *appD;        
    appD = [UIApplication sharedApplication];

    if(appD.sw1.on)
        NSLog(@"It is ON");
    else
        NSLog(@"It is OFF");

Error compiling. It works without warning, but it does not work.

I do not understand what the problem is.

...

EDIT: OMG, should also have called a delegation method:

appD = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
+3
source share
2 answers

I recommend you this way to share the application delegate: https://coderwall.com/p/z4h4uw?i=2&p=1&q=&t%5B%5D=%21%21mine&t%5B%5D=%21%21bookmarks

+2
source

and created an instance of appDelegate ...

No, you did not create anything, you just declared a variable that could point to the delegate of your application. But you have not assigned anything to this variable yet.

, . :

appD = (myAppDelegate *)[[UIApplication sharedApplication] delegate];

(Btw, . .)

+1

Source: https://habr.com/ru/post/1793313/


All Articles