Contents

UICalendarSelectionWeekOfYear

An object that tracks a specific week a person selects from a calendar view.

Declaration

@MainActor class UICalendarSelectionWeekOfYear

Overview

Use the UICalendarSelectionWeekOfYear selection behavior to allow selecting dates in a calendar view by week. The following code example shows how to configure a calendar view’s selection behavior to use week-of-year selection:

// Create a calendar view.
let calendarView = UICalendarView()
calendarView.calendar = Calendar(identifier: .gregorian)

// Set the selection behavior.
let selection = UICalendarSelectionWeekOfYear(delegate: self)
calendarView.selectionBehavior = selection

// Set the 11th week in the year 2024.
selection.selectedWeekOfYear = DateComponents(
    calendar: Calendar(identifier: .gregorian),
    weekOfYear: 11,
    yearForWeekOfYear: 2024)

Topics

Creating a week-of-year selection

Setting the selection delegate

Updating the selected week

See Also

Handling date selections