Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6662765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:25:32+00:00 2026-05-26T02:25:32+00:00

I’m currently trying learning Cocoa and I am not sure if I understand that

  • 0

I’m currently trying learning Cocoa and I am not sure if I understand that correctly… It’s about delegates and controllers.

At first: What’s the difference between the two? Sometimes I see code where a class is called AppController, sometimes – with more or less the same content – AppDelegate.

So, if I understand it correctly, a delegate is a simple object that receives messages when a certain event occurs. For example:

@interface WindowController : NSObject <NSWindowDelegate>
@end

@implementation WindowController
- (void)windowDidMiniaturize:(NSNotification *)notification {
    NSLog(@"-windowDidMiniaturize");
}
@end

Now, I use this code to make it a delegate of my window:

@interface TryingAppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
}

@property (assign) IBOutlet NSWindow *window;
@property (retain) WindowController *winController;

@end

With the following implementation:

@implementation TryingAppDelegate

@synthesize window;
@synthesize winController;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSLog(@"-applicationDidFinishLaunching:");

    self.winController = [[WindowController alloc] init];
    [window setDelegate:winController];

    [self.winController release];
}

@end

And now, whenever I minimize window, it will send a -windowDidMiniaturize: message to WindowController. Do I have that right?

If so, why don’t you just subclass NSWindow rather than bothering with an additional class you have to take care of?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:25:32+00:00Added an answer on May 26, 2026 at 2:25 am

    Delegates are especially useful when you want one object to coordinate several others. For instance, you might create an NSWindowController subclass and make it it’s window’s delegate. That same window might contain several other elements (like NSTextFields) that you want to make the window controller a delegate of. This way you don’t need to subclass the window and several of its controls. You can keep all the code that conceptually belongs together in the same class. In addition, delegates usually belong to the controller level of the Model-View-Controller concept. By subclassing NSWindow you would move controller type code to the view level.

    A class can adopt any number of protocols, so <NSWindowDelegate, NSTextFieldDelegate> is perfectly valid. You can then set your object as the delegate of any number of windows and text fields. To find out what delegate messages a class like NSTextField supports check out the class reference.The -delegate and -setDelegate: methods will usually point you to the proper protocol. In our case this is NSTextFieldDelegate. For classes that have been added to older version of Apple’s frameworks there often an additional section on delegate methods (either alongside “Class Methods” and “Instance Methods” or as a subsection of “Tasks”). Note that declaring your class as conforming to a delegate protocol will not have them magically delivered to your object – you must explicitly set it as the delegate:

    @interface MyWindowController : NSWindowController <NSWindowDelegate, NSTextFieldDelegate> {
        NSTextField *_someTextField;
    }
    
    @property (nonatomic, retain) IBOutlet NSTextField *someTextField;
    
    @end
    
    
    @implementation MyWindowController
    
    @synthesize someTextField = _someTextField;
    
    - (void)dealloc {
        [_someTextField release];
        [super dealloc];
    }
    
    - (void)windowDidLoad {
        [super windowDidLoad];
        // When using a XIB/NIB, you can also set the File's Owner as the
        // delegate of the window and the text field.
        [[self window] setDelegate:self];
        [[self someTextField] setDelegate:self];
    }
    
    - (void)windowDidMiniaturize:(NSNotification *)notification {
    
    }
    
    - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor {
        return YES;
    }
    
    @end
    

    AppController and AppDelegate are just different naming conventions for the same type of class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.