Well, this may seem like a hoax, but if you carry with me and read the whole question, you will understand why I ask about it.
I have seen many good examples and explanations on the Internet and here, but I just cannot get it. It is important for me to understand whys and 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 lots of examples ), because then I just do not understand.
I would like two classes - a garden. It has an array with flowers, each flower is created from flowerClass. Thus, flowerClass does not know which garden it created. He just screams about water sometimes.
So, if someone here can explain this to me, I would be very grateful!
I tried, and now I'm going down based on the information I received 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 did not import any UIKit or foundations because I was trying to just do the delegate related stuff here now ... So, is that right?