I need to call some other function when UIButton is pressed (in my case pass data from UIDatePicker and UITextField to EKCalendar to create an event, so I can not just write it inside IBAction func {}) Here is my function:
func insertEvent(store: EKEventStore) {
let calendars = store.calendarsForEntityType(EKEntityTypeEvent)
as! [EKCalendar]
for calendar in calendars {
if calendar.title == "todo" {
let startDate = myDatePicker.date
let endDate = startDate.dateByAddingTimeInterval(2 * 60 * 60)
// Create Event
var event = EKEvent(eventStore: store)
event.calendar = calendar
event.title = nameTextField.text
event.startDate = startDate
event.endDate = endDate
// Save Event in Calendar
var error: NSError?
let result = store.saveEvent(event, span: EKSpanThisEvent, error: &error)
if result == false {
if let theError = error {
println("An error occured \(theError)")
}
}
}
}
}
What should I write in :
@IBAction func addReminder(sender: UIButton) {
}
to call my function I wrote above.
I've tried just call it by typing insertEvent()
inside IBAction func {}
, but in gives me warning "missing argument for parameter #1 in call..." also tried to call in with parameter and it also gives me warning...
I also tried to create an outlet for button (not action) type of segue and then access in with
func addReminder(sender: UIButton) {
if sender === addReminder {}
}
but it gives me the same errors... what a curse!
How could I assign this function to a button, maybe there is another way?
P.S.: I am Xcode 6.3