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 5968559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:06:26+00:00 2026-05-22T20:06:26+00:00

Ok, this may seem like a dupe question, but if you bear with me

  • 0

Ok, this may seem like a dupe question, but if you bear with me and read the whole question, you see why I ask it.

I have seen many nice examples and explanations on the web and here as well, but I just cant get it. Its important for me to understand the whys and the hows, so instead of using some example from the documentation (BTW, I really suck when it comes to understanding Apple Docs, Im used with php.net documentation, with abundance of examples) because then I just don’t understand it.

I would like two classes, a gardenClass. It has an array with flowers, each flower is instantiated from the flowerClass. So, the flowerClass does not know what kind of garden instantiated it. It just screams for water sometimes.

So, if someone here could explain this for me, I would be really grateful!

I tried out and here is me having a go based on the info I got from you guys:

MyGarden.h

#import "Flower.h"

@interface MyGarden : NSObject <WateringDelegate>
{
    Flower *pinkFlower;
}
@end

MyGarden.m

#import "MyGarden.h"
#import "Flower.h"

@implementation MyGarden

- (void) giveWaterToFlower
{
    NSLog(@"Watering Flower");
}

- (void)viewDidLoad
{
    pinkFlower = [[Flower alloc] init];
    [pinkFlower setDelegate:self];
    [pinkFlower startToGrow];
}
@end

Flower.h

@protocol WateringDelegate <NSObject>
@required
- (void) giveWaterToFlower;
@end

@interface Flower : NSObject
{
    id <WateringDelegate> delegate;
}

@property (retain) id delegate;
- (void) startToGrow;
@end

Flower.m

#import "Flower.h"

@implementation Flower

@synthesize delegate;

- (void) needWater
{
    [[self delegate] giveWaterToFlower];
}

- (void) startToGrow
{
    [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(needWater) userInfo:nil repeats:YES];
}
@end

I have not imported any UIKit or foundation, beause I tried to just do the stuff thats related to delegates here now…
So, is this correct?

  • 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-22T20:06:27+00:00Added an answer on May 22, 2026 at 8:06 pm

    A delegate is where you implement custom behavior for your app, that affects how another class (such as a plain-old object in the Cocoa framework) does its work.

    In other languages that don’t use the delegates pattern you might subclass an object to change its behavior. Objective-C lets you do that as well, but the benefit of a delegate is that you don’t have to subclass each time you want to make a minor change, an object can be a delegate for multiple other objects.

    So consider a controller class that owns a window with some controls, maybe a table of information, a toolbar, etc. You can set the controller to be the delegate of those controls, so that when the controls need more information about what they’re supposed to do they can look to your controller. You might want to customize how the window is resized, what happens when the user selects a row in the table view, how information is presented, and so on. Those are all calls the controls make to their delegate (your controller), using methods defined in their delegate protocol. If you’re lucky you can write all your custom code without having to subclass and split things up into multiple files.

    Another benefit is that you only need to implement the delegate methods you care about. If the default behavior is fine, there’s nothing you need to do.

    So in your example, the flower class would have some sort of delegate protocol with a “waterMe” method. The delegate (maybe the garden class, or something else altogether) could implement this however you choose, and it would only be called when the flower class needs it to. It’s worth noting though that delegation is most useful in frameworks, where you have an object that works in a generic way that may be overridden to accomplish different things. In your own code it’s usually more straightforward to add that custom behavior right to your own object, unless you truly are going to be using it in a generic way. In other words, don’t be tempted to spend the time making a class that can behave generically when in reality you’re only going going to make it behave in one specific way.

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

Sidebar

Related Questions

This may seem like a dumb question but I have IDLE and I'm trying
This may seem like a very simple question, but I have been struggling with
This may seem like a silly question, but I thought I'd ask it anyway
Ok this may seem like a bit of a noob question but one many
this may seem like a stupid question but I have a query string which
This may seem like a weird question but thought I would ask here before
this may seem like a very basic question, but i have difficulty grasping it,
This may seem like a stupid Question but i have two cubes being rendered
This may seem like a simple question but i am getting an error when
This may seem like a stupid question, but what message do i send to

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.