I've got a kind of genereal question about the delegate concept. I've seen an code example where basically (VC = ViewController) VC1 opens VC2 and passes, via segue, an object to it. VC2 modifies the object and passes it back to vc1, then closes itself.
VC2 has got a @property (assign, nonatomic) id<DismissViewDelegate> delegate;
property. Before VC1 opens VC2 via segue, it sets VC2.delegate = self;
. VC1 and VC2 both implement the following protocol:
DismissViewDelegate.h
@protocol DismissViewDelegate <NSObject>
-(void)dismissWithProdukt:(Produkt*)produkt;
@end
My question is, as I'm new to self created delegates and protocols, how is this approach different than giving VC2 a weak pointer to VC1, like:
@property (weak, nonatomic) VC1 *firstVC;
So that I could say:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
VC2 *vc2 = *dvc = segue.destinationViewController;
vc2.firstVC = self;
}
Then, after modifying the object, I would, from VC2, pass the object like firstVC.object = self.object
and then close VC2.
Are these two approaches different from the result? Or does the second solution work at all? Where would the advantage of the delegate approach be? Thanks a lot!