Array<NSNumber> not working for EKRecurringRule in EventKit

I am having an issue here with the NSNumber Type using with SwiftUI and I am not sure what I am doing wrong here?

@State private var recurringMonthsTest: NSNumber = 1`
       
 let rule = EKRecurrenceRule(
            recurrenceWith: recurringOn,
            interval: recurringInterval,
            daysOfTheWeek: [EKRecurrenceDayOfWeek.init(EKWeekday.monday)],
            daysOfTheMonth: [],
            monthsOfTheYear: [recurringMonthsTest],
            weeksOfTheYear: [],
            daysOfTheYear: [],
            setPositions: nil,
            end: EKRecurrenceEnd.init(occurrenceCount: 8))
    }

Here is some basic Code to explain the issue, if you look at the above code it works well, I can also put 2 or more NSNumber single values inside the rule.

But if I start to use the Array as below

let recurringMonthsTest2: Array<NSNumber> = [recurringMonthsTest, recurringMonthsTest1]
 let rule = EKRecurrenceRule(
            recurrenceWith: recurringOn,
            interval: recurringInterval,
            daysOfTheWeek: [EKRecurrenceDayOfWeek.init(EKWeekday.monday)],
            daysOfTheMonth: [],
            monthsOfTheYear: [recurringMonthsTest2],
            weeksOfTheYear: [],
            daysOfTheYear: [],
            setPositions: nil,
            end: EKRecurrenceEnd.init(occurrenceCount: 8))
    }

It doesn't compile and I get the below error which I don't understand.

`Cannot convert value of type 'Array<NSNumber>' to expected element type 'Array<NSNumber>.ArrayLiteralElement' (aka 'NSNumber')

As I understand both are of the same value but why they don't compile?

I tried already several versions like [NSNumber] = [] but everything is failing...

What am I doing wrong here, can anyone help?

Answered by marc1881 in 800509022

Oh my, it was actually too late... I made a stupid mistake by not removing the Brackets [] ...

Accepted Answer

Oh my, it was actually too late... I made a stupid mistake by not removing the Brackets [] ...

Array&lt;NSNumber&gt; not working for EKRecurringRule in EventKit
 
 
Q