title: How can I save event array into iCalendar
body: <p>I've some code for insert event</p>
  <pre><code>     for event in events {
                  for ct in 0..&lt;self.holidayArray!.count {
                      if self.dateFormatter2.string(from: event.startDate) == self.holidayArray?[ct].start?.date &amp;&amp; event.title == self.holidayArray?[ct].summary {
                          print(&quot;\(event.title)&quot;)
                          clue = &quot;same data with iCal&quot;
                          //skip data
                      } else { //save data into iCal
                          let startDate = self.holidayArray?[ct].start?.date
                          let endDate = self.holidayArray?[ct].end?.date
                          event.title = self.holidayArray?[ct].summary
                          event.startDate = self.dateFormatter2.date(from: startDate!)
                          print(self.dateFormatter2.date(from: startDate!))
                          event.endDate = self.dateFormatter2.date(from: endDate!)
                          print(self.dateFormatter2.date(from: endDate!))
                          print(event.notes)
                          event.calendar = store.defaultCalendarForNewEvents
                          
                          do {
                              print(&quot;\nTITLE = \(event.title)&quot;)
                              try self.eventStore.save(event, span: .thisEvent)
                              print(&quot;Saved Event\n&quot;)
                          } catch let error as NSError {
                              print(&quot;failed to save event with error : \(error)&quot;)
                          }
                      }
                  }
              }
  </code></pre>
  <p>when the code running, sometimes data that i want to save goes into <code>error</code> with details <code>EKErrorDomain Code=11 EKErrorObjectBelongsToDifferentStore</code> and some data that can be saved is having repeating name.
  Here's the screenshot that having problem
  [1]: <a href="https://i.stack.imgur.com/TtrIf.png" rel="nofollow noreferrer">https://i.stack.imgur.com/TtrIf.png</a>
  [2]: <a href="https://i.stack.imgur.com/yIiyQ.png" rel="nofollow noreferrer">https://i.stack.imgur.com/yIiyQ.png</a></p>
  <p>How can i fix it?
  Thank you.</p>