I've looked through your code and one solution could be to add the value of your segmentedControl
as a parameter to your TodoItem
as you already do now in the gentag
parameter.
Then in your addItem
method you "just" need to convert from the Int
value you have now to a NSCalendarUnit
which you can hand to your notification.repeatInterval
.
To keep this pretty you could create a new Enum
who knew how to convert from Int
to NSCalendarUnit
values, and then your gentag
parameter could be of this type.
So in the file where you have your TodoSchedulingViewController
you could write something like this in the top of the file:
import UIKit
enum RepeatInterval: Int {
case None = 0
case Daily = 1
case Weekly = 2
func toCalendarUnit() -> NSCalendarUnit {
switch self {
case .None:
return NSCalendarUnit(rawValue: 0)
case .Daily:
return NSCalendarUnit.Day
case .Weekly:
return NSCalendarUnit.Weekday
}
}
}
class TodoSchedulingViewController: UIViewController {
...
Which you could then use like this:
In your ViewController
:
let todoItem = TodoItem(deadline:....,
title:....,
gentag: RepeatInterval(rawValue: segmentedControl.selectedSegmentIndex)!, //You can force unwrap here, because you know the value is always one you get from your segmentedControl
UUID......)
In your TodoList
class:
...
notification.userInfo = ["title" : item.title, "UUID" : item.UUID]
notification.repeatInterval = item.gentag.toCalendarUnit()
Hope that makes sense.
Oh...and next time, please post your actual code instead of images, it makes it easier to quickly see what is going on and way faster to copy code snippets from your code into an answer :)