Sunday, August 14, 2022
HomeiOS Developmentios - Calendar.present.part(.12 months, from: Date()) returns 4 as a substitute of...

ios – Calendar.present.part(.12 months, from: Date()) returns 4 as a substitute of 2022

We have now a web page on our app during which the person can chosen a 12 months from an inventory. The listing incorporates all years from 1900 to 2022.
Some customers have reported that they do not see the listing in any respect. We could not determine how this occurred, so we added a non-fatal problem report that’s despatched to Crashlytics at any time when the preliminary situations for displaying the listing aren’t met.

That is the related code:

personal lazy var currentYear: Int = {
    Calendar.present.part(.12 months, from: Date())

personal lazy var yearsArray: [String] = {
    if currentYear < 1900 {
        NSError(area: "OTP_YEAR", code: 1, userInfo: [NSLocalizedDescriptionKey: "CurrentYear < 1900. value: (currentYear), Date: (Date())"])
        return []
    let outcome = (1900 ... currentYear).map { String($0) }
    if outcome.isEmpty {
        NSError(area: "OTP_YEAR", code: 2, userInfo: [NSLocalizedDescriptionKey: "Empty years array. currentYear: (currentYear), Date: (Date())"])
    if outcome.incorporates(the place: { $0.trimWhiteSpacesAndNewLine().isEmpty }) {
        NSError(area: "OTP_YEAR", code: 3, userInfo: [NSLocalizedDescriptionKey: "Years array contains empty strings. currentYear: (currentYear), Date: (Date()), Array: (result)"])
    return outcome

After just a few weeks it occurred once more and this time we may see the next occasion reported:

nserror-code: 1
nserror-domain: OTP_YEAR
NSLocalizedDescription: CurrentYear < 1900. worth: 4, Date: 2022-07-11 12:59:00 +0000

This occurred to 2 of our customers, each with iPhone 13 and iOS 15.5

In response to the logs, if I perceive them appropriately, the usual documented method of extracting the 12 months part, Calendar.present.part(.12 months, from: Date()), returns 4 as a substitute of the present 12 months.

We won’t reproduce this case on our check gadgets. Any concept why this occurs to a number of the customers?



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments