title: FSCalender Events Show in swift
body: <p>I am new to swift, Am using Fscalender in swift it's working fine, But I want add the Events to Fscalender, I can get events from Json </p>
  
  <p><a href="https://i.stack.imgur.com/Jc3Ar.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jc3Ar.png" alt="enter image description here"></a> </p>
  
  <p>I Want Display the events in calender, I can try some of the code but its not working getting some errors pls help how to display events in calender </p>
  
  <pre><code>   var EventsData = [Event]()
  
    all events are stored Into Event
  
  
     fileprivate lazy var dateFormatter2: DateFormatter = {
          let formatter = DateFormatter()
          formatter.dateFormat = "yyyy-MM-dd"
  
  
  
          return formatter
      }()
  </code></pre>
  
  <p>inside Json </p>
  
  <pre><code>        if let event_list = jsonData["events"] as? NSArray {
  
                                  for i in 0 ..&lt; event_list.count {
  
                                      if let event = event_list[i] as? NSDictionary {
  
  
                                         let data = event["date"]as?String
  
                                          let newString = data?.replacingOccurrences(of: "/", with: "-")
  
                                          print("new string data ",newString as Any)
  
                                         self.compareDate(date: newString!)
  
                                          self.EventsData.append(Event(
                                              eventId: event["eventId"] as? String,
                                              eventName:event["details"] as? String,
                                              //eventDate: event["date"] as? String
                                               eventDate: newString ))
                                      }
  
  
                                  }
   }
  </code></pre>
  
  <p>Display the Events </p>
  
  <pre><code>         func compareDate(date : String){
                  let date = date
  
                  let dateFormatter = DateFormatter()
                  dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
                  let dateFromString : NSDate = dateFormatter.date(from: date)! as NSDate
  
   ===&gt;&gt;   After this line showing Fatal error 
  
                  dateFormatter.dateFormat = "yyyy-MM-dd"
                  let datenew = dateFormatter.string(from: dateFromString as Date)
                  print("datee",datenew)
  
              }
  
  
              func calendar(_ calendar: FSCalendar, willDisplay cell: FSCalendarCell, for date: Date, at position: FSCalendarMonthPosition) {
  
                  let dateFormatter3 = DateFormatter()
  
                  dateFormatter3.dateFormat = "yyyy-MM"
                  let dateString3 = dateFormatter3.string(from: date)
  
                  //print("datenew1",dateString3)
  
  
                  strcond  = dateString3 as NSString
  
                  print("datenew1",strcond!)
  
              }
  
              func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -&gt; Int {
                  let dateString = self.dateFormatter2.string(from: date)
  
                  for d in EventsData{
                      let date = d.eventDate
  
  
                      let dateFormatter = DateFormatter()
                      dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
                      let dateFromString : NSDate = dateFormatter.date(from: date!)! as NSDate
                      dateFormatter.dateFormat = "yyyy-MM-dd"
                      let datenew = dateFormatter.string(from: dateFromString as Date)
                      if datenew.contains(dateString) {
                          return 1
                      }
                  }
                  return 0
  
              }
  
              func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, eventColorFor date: Date) -&gt; UIColor? {
                  let dateString = self.dateFormatter2.string(from: date)
  
  
                  for d in EventsData{
                    let date = d.eventDate
  
                      let dateFormatter = DateFormatter()
                      dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
                      let dateFromString : NSDate = dateFormatter.date(from: date!)! as NSDate
                      dateFormatter.dateFormat = "yyyy-MM-dd"
                      let datenew = dateFormatter.string(from: dateFromString as Date)
  
  
                      print("new  calendar",dateString)
  
  
                      if datenew.contains(dateString) {
                          return UIColor.purple
                      }
                  }
                  return nil
              }
  
  
              func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
                  if monthPosition == .previous || monthPosition == .next {
                      calendar.setCurrentPage(date, animated: true)
  
                      print("title date",date)
                  }
              }
  </code></pre>
  
  <p>how to show events in calendar ?          </p>