Gold Challenge - Solution


#1

I re-declared item in BNRItem as property so that both getter and setter are available to us. Manual getter/setter look ugly IMO.

@property (strong, nonatomic) NSDate *dateCreated;
Add another ViewController BNRDateChanger:

#BNRDateChanger.h

#import <UIKit/UIKit.h>
@class BNRItem;

@interface BNRDateChanger : UIViewController
@property (strong, nonatomic) BNRItem *item;

@end[/code]

BNRDateChanger.m

[code]#import "BNRDateChanger.h"
#import "BNRItem.h"
#import "BNRDetailViewController.h"

@interface BNRDateChanger ()
@property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;

@end

@implementation BNRDateChanger

- (void)viewDidLoad
{
	[self.datePicker addTarget:self action:@selector(updateDate:) forControlEvents:UIControlEventValueChanged];

}


- (void)updateDate:(id)obj
{
	BNRItem *item = self.item;
	item.dateCreated = self.datePicker.date;
	
}



@end

In BNRDetailsViewController:

- (IBAction)changeDate:(id)sender { BNRDateChanger *dateChanView = [[BNRDateChanger alloc] init]; dateChanView.item = _item; [self.navigationController pushViewController:dateChanView animated:YES]; }

Good Fun! :smiley:


#2

I think something is missing in your solution. Where does UpdateDate() get called? Do I need to change something in BNRDetailViewController.xib or what?