-2

I need to subtract 15 minutes from a date. Note understanding why following is not working:

eventDate = event.date;
            NSDate *alarmDate = [[eventDate] dateByAddingTimeInterval:-60*15];//this is throwing error "Expected identifier"

Thanks for any suggestions.

user1904273
  • 4,562
  • 11
  • 45
  • 96
  • 1
    Get rid of the needless brackets around `eventDate`. – rmaddy Sep 16 '15 at 00:28
  • Did not fix problem. Code is from this answer that received 9 votes. http://stackoverflow.com/questions/12420199/how-to-subtract-1-hour-from-a-given-date-time. Funny how random SO ratings are. – user1904273 Sep 16 '15 at 00:36
  • 1
    Huge difference. Those brackets are for calling a method. Your brackets around `evenDate` are invalid and causing your error. – rmaddy Sep 16 '15 at 00:37
  • why would you comment on question and then try to close it? Thank you Abhi for actually answering the question. – user1904273 Oct 15 '15 at 00:12

1 Answers1

5

You've got a syntax error in your code, square braces must only be used when you are sending a "message" to an object. Do not use Objective-C square brace syntax in any other situation.

Here is the correct code:

eventDate = event.date;
NSDate *alarmDate = [eventDate dateByAddingTimeInterval:-60*15];
Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110