0

I am trying to create code that tests wether the date selected in a UIDatePicker is equal to the current date. I am tying to get it to act as an alarm clock (user selects a time, they press a button, and an alert is displayed when that time is reached). Thanks! Here is my code:

#import "AlarmViewController.h"

@interface AlarmViewController ()

@end

@implementation AlarmViewController

NSDate *selectedDate;
NSDate *now;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

 - (void)viewDidLoad
{
    [super viewDidLoad];
    now = [NSDate date];
[_setDatePicker setDate:now animated:YES];
}

    - (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)setAlarm:(id)sender {
selectedDate = [_setDatePicker date];
[self checkDate];

}
-(void)checkDate{
if(selectedDate == now){
        NSString *message = [[NSString alloc]initWithFormat:@"The date and time you selected   
is:    %@", selectedDate];
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"time selected" message:message   
delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert show];
}
}
@end
Larme
  • 24,190
  • 6
  • 51
  • 81

0 Answers0