Repository: Automattic/pocket-casts-ios
File: podcasts/Notifications/NotificationsCoordinator.swift (Swift)

Code before:
    }

    // Variable to be used only in debugging/testing to accelarate notifications schedule
    static var speedUpNotifications: Bool = false

    var timeIntervalStep: TimeInterval {
        switch self {
            case .newEpisodes:
                return 0
            case .dailyReminders:
                return Self.speedUpNotifications ? 10.seconds: 24.hours
            case .recommendations:
                return Self.speedUpNotifications ? 60.seconds: 3.days
            case .newFeaturesAndTips:
                return Self.speedUpNotifications ? 60.seconds: 1.week
            case .offers:
                return Self.speedUpNotifications ? 120.seconds: 2.week
        }
    }

    func trigger(order: Int, notification: NotificationType) -> UNNotificationTrigger? {
        if Self.speedUpNotifications {
            return UNTimeIntervalNotificationTrigger(timeInterval: Double(order + 1) * timeIntervalStep, repeats: notification.isRepeatable)
        }
        let todayComponents = Calendar.current.dateComponents(in: .current, from: Date.now)
        let todayWeekday: Int = todayComponents.weekday ?? 1
        let maxWeekDays: Int = Calendar.current.weekdaySymbols.count
        var triggerWeekDay = todayWeekday
        switch self {
            case .newEpisodes:
                return nil
            case .dailyReminders:
                let timeIntervalToSchedule: TimeInterval = calculateTimeIntervalToHour(scheduleHour)
                return UNTimeIntervalNotificationTrigger(timeInterval: timeIntervalToSchedule + (Double(order) * timeIntervalStep), repeats: notification.isRepeatable)
            case .recommendations:
                // Follow three days
                triggerWeekDay = ((todayWeekday + ((order+1)*3)) % maxWeekDays)
            case .newFeaturesAndTips:
                // Follow two days
                triggerWeekDay = ((todayWeekday + ((order+1)*2)) % maxWeekDays)
            case .offers:
                // One week from now
                triggerWeekDay = ((todayWeekday - order - 1) % maxWeekDays)
        }

        if triggerWeekDay == 0 {
            triggerWeekDay += 1
        }
        let dateComponents = DateComponents(hour: scheduleHour, weekday: triggerWeekDay)
        return UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: notification.isRepeatable)
    }

Review comment (suggestion):
I believe you can avoid the optional here:

```suggestion
        let todayWeekday = Calendar.current.component(.weekday, from: Date.now)
```

Code after:
    }

    // Variable to be used only in debugging/testing to accelarate notifications schedule
    static var speedUpNotifications: Bool = false

    var timeIntervalStep: TimeInterval {
        switch self {
            case .newEpisodes:
                return 0
            case .dailyReminders:
                return Self.speedUpNotifications ? 10.seconds: 24.hours
            case .recommendations:
                return Self.speedUpNotifications ? 60.seconds: 3.days
            case .newFeaturesAndTips:
                return Self.speedUpNotifications ? 60.seconds: 1.week
            case .offers:
                return Self.speedUpNotifications ? 120.seconds: 2.week
        }
    }

    func trigger(order: Int, notification: NotificationType) -> UNNotificationTrigger? {
        if Self.speedUpNotifications {
            return UNTimeIntervalNotificationTrigger(timeInterval: Double(order + 1) * timeIntervalStep, repeats: notification.isRepeatable)
        }
        let calendar = Calendar.current
        let maxWeekDays: Int = calendar.weekdaySymbols.count
        switch self {
            case .newEpisodes:
                return nil
            case .dailyReminders:
                let timeIntervalToSchedule: TimeInterval = calculateTimeIntervalToHour(scheduleHour)
                return UNTimeIntervalNotificationTrigger(timeInterval: timeIntervalToSchedule + (Double(order) * timeIntervalStep), repeats: notification.isRepeatable)
            case .recommendations:
                return makeTrigger(
                    days: (order + 1) * 3,
                    from: .now,
                    calendar: calendar,
                    repeats: notification.isRepeatable
                )

            case .newFeaturesAndTips:
                return makeTrigger(
                    days: (order + 1) * 2,
                    from: .now,
                    calendar: calendar,
                    repeats: notification.isRepeatable
                )

            case .offers:
                return makeTrigger(
                    days: maxWeekDays - order - 1,