title: Set recurrence of Event "repeats every month" instead of "repeats every month, each 31st" ios
body: <ol>
  <li>I am setting an event for say the 13th of some month and recur it every month. It is getting repeated properly every month.
  But when set it for 31st of some month it gets set for months with 31st only and in event it shows in Edit->Repeat->repeats every month, each 31st.</li>
  <li>I want it to set for at least last day month if no date 31st available for that month.</li>
  <li>Also for the month of February no 29, 30, or 31 then also the event from other months with these dates are not created.</li>
  </ol>
  
  <p>Please note that we wanted to set continuous set of events so that deleting and editing them would be easy.</p>
  
  <p>I wrote the following code:</p>
  
  <pre><code>let eventstore : EKEventStore = EKEventStore()
          eventstore.requestAccess(to: EKEntityType.event, completion: { (isallow, error) -&gt; Void in
              var event:EKEvent!
  
              if (event == nil) {
                  event = EKEvent(eventStore: eventstore)
                  event.title = self.getReminderTitleForCalendarEvent(dtDate: date)
                  event.notes = ""
                  event.startDate = date
                  event.endDate = date
                  event.calendar = eventstore.defaultCalendarForNewEvents
                  let ekrules: EKRecurrenceRule = EKRecurrenceRule.init(recurrenceWith: EKRecurrenceFrequency.monthly, interval:self.selectedFrequency!, end: nil)
                  event.recurrenceRules = [ekrules]
              }
              else // if there is already a event then update date
              {
  
                  // if event is deleted by user
                  event.startDate = date
                  event.endDate = date
                  if let oldalarm = event.alarms?[0]// remove old date alarm
                  {
                      event.removeAlarm(oldalarm)
                  }
                  // Below code is to remove existing event
                  do
                  {
                      try  eventstore.remove(event, span: .thisEvent)
                      //self.objselectedinfusion.strEventId = event.eventIdentifier
                  }
                  catch let error as NSError {
                      //print(error.localizedDescription)
                  }
              }
              let alarm = EKAlarm(relativeOffset: self.getTimeIntervalForAlert())
  
     let alarm = EKAlarm(absoluteDate: reminderFireDate as Date)
    event.addAlarm(alarm)
  
              do
              {
                  try eventstore.save(event, span: EKSpan.futureEvents, commit: true)
                  UserDefaults.standard.set(event.eventIdentifier, forKey: Constant.calendarEventID)
              }
              catch let error as NSError {
                  //print(error.localizedDescription)
              }
  
          })
  </code></pre>
  
  <p>Here <code>selectedFrequency</code> is recurrence interval that is some number of months.</p>