0

Sorry for posting about this but I have been wrestling with it for sometime, I have been trying to use the timeIntervalSinceDatebut its not behaving. This is the m file:

#import "ViewController.h"

@interface ViewController()

   @end

   @implementation ViewController //warning: Method definition for 'timeIntervalSinceDate:' not found

-(IBAction) setButtonTapped:(id)sender {

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date ];
NSLog( @"Set button tapped : %@", dateTimeString );

NSDate* currentDate = [NSDate date];
NSTimeInterval secs = [dateTimeString timeIntervalSinceDate:currentDate]; //error: No visible @interface for 'NSString' declares the selector 'timeIntervalSinceDate:’
NSLog(@"Seconds %f", secs);

[self scheduleLocalNotificationWithDate: dateTimePicker.date];

[self presentMessage:@"succesfully set!"];

}

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

@end

and this is the h file:

#import <UIKit/UIKit.h>
#import <AvFoundation/AVFoundation.h>

@interface ViewController : UIViewController <AVAudioPlayerDelegate>
{
    IBOutlet UIDatePicker *dateTimePicker;
}
- (NSTimeInterval)timeIntervalSinceDate:dateTimePicker;
-(IBAction) setButtonTapped:(id)sender;

@end

Also what would the method be for timeIntervalSinceDate? I couldn't find any info on it and as I'm new to this want sure how to work it out for myself.

Thanks

crazy_tiger_corp
  • 271
  • 3
  • 22

3 Answers3

3

You are calling timeIntervalSinceDate: from NSString which is a method of NSDate. Convert NSString to NSDate using NSDateFormatter and call the function timeIntervalSinceDate: or in your case use the dateTimePicker.date itself. Don't convert it to NSString

abintom
  • 1,008
  • 7
  • 6
3

Your are trying to perform a method of NSDate on an NSString object (dateTimeString). Convert it to NSDate format first and then call the 'timeIntervalSinceDate:' method on the NSDate object.

Refer this post on how to convert NSString to NSDate.

Converting NSString to NSDate (and back again)

Community
  • 1
  • 1
Skywalker
  • 1,590
  • 1
  • 18
  • 36
2

timeIntervalSinceDate is method from NSDate class and is documented here

You are calling the method on wrong type NSString which basically the error tells you.

deimus
  • 9,565
  • 12
  • 63
  • 107