<!--
{
  "availability" : [
    "macOS: 10.3.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebHistory",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WebHistory"
  },
  "title" : "WebHistory"
}
-->

# WebHistory

`WebHistory` objects are used to maintain the pages visited by users. Visited pages are represented by [`WebHistoryItem`](/documentation/WebKit/WebHistoryItem) objects. You add and remove history items using the [`addItems(_:)`](/documentation/WebKit/WebHistory/addItems(_:)) and [`removeItems(_:)`](/documentation/WebKit/WebHistory/removeItems(_:)) methods. These methods post appropriate notifications when items are added or removed so you can update the display. `WebHistory` organizes the `WebHistoryItem` objects by the day they were visited, ordered from most recent to oldest. You can request all the days that contain history items using the [`orderedLastVisitedDays`](/documentation/WebKit/WebHistory/orderedLastVisitedDays) method or request the items visited on a particular day using the [`orderedItemsLastVisited(onDay:)`](/documentation/WebKit/WebHistory/orderedItemsLastVisited(onDay:)) method. `WebHistory` objects can be loaded and saved by specifying a file URL (see [`load(from:)`](/documentation/WebKit/WebHistory/load(from:))).

```
class WebHistory
```

## Topics

### Accessing Shared History Objects

[`+  optionalSharedHistory`](/documentation/WebKit/WebHistory/optionalShared())

Returns a shared web history object, if one exists.

[`+  setOptionalSharedHistory:`](/documentation/WebKit/WebHistory/setOptionalShared(_:))

Sets the web history object to share.

### Adding and Removing History Items

[`-  addItems:`](/documentation/WebKit/WebHistory/addItems(_:))

Inserts or updates the specified items in the web history.

[`-  removeItems:`](/documentation/WebKit/WebHistory/removeItems(_:))

Removes the specified items from the web history.

[`-  removeAllItems`](/documentation/WebKit/WebHistory/removeAllItems())

Removes all items from the web history.

### Getting Web History Items

[`-  orderedItemsLastVisitedOnDay:`](/documentation/WebKit/WebHistory/orderedItemsLastVisited(onDay:))

Returns web history items that were last visited on the specified date.

[`orderedLastVisitedDays`](/documentation/WebKit/WebHistory/orderedLastVisitedDays)

An array of all calendar days represented in the web history.

[`-  itemForURL:`](/documentation/WebKit/WebHistory/item(for:))

Returns the web history item that corresponds to the specified web location.

### Loading and Saving History Information

[`-  loadFromURL:error:`](/documentation/WebKit/WebHistory/load(from:))

Loads the contents of the specified web history file.

[`-  saveToURL:error:`](/documentation/WebKit/WebHistory/save(to:))

Saves the web history to the specified file.

### Getting and Setting Attributes

[`historyAgeInDaysLimit`](/documentation/WebKit/WebHistory/historyAgeInDaysLimit)

The maximum age of web history items that can be retrieved.

[`historyItemLimit`](/documentation/WebKit/WebHistory/historyItemLimit)

The maximum number of web history items that can be stored.

### Constants

[Web History Dictionary Keys](/documentation/WebKit/web-history-dictionary-keys)

The key for accessing the web history items stored in a notification’s user information dictionary.

### Notifications

[`WebHistoryAllItemsRemovedNotification`](/documentation/WebKit/WebHistoryAllItemsRemovedNotification)

Posted when all history items have been removed from the web history.

[`WebHistoryItemChangedNotification`](/documentation/WebKit/WebHistoryItemChangedNotification)

Posted by a WebHistoryItem object when the value of the history item’s title, alternate title, URL strings, or last visited interval changes.

[`WebHistoryItemsAddedNotification`](/documentation/WebKit/WebHistoryItemsAddedNotification)

Posted when history items have been added to a web history.

[`WebHistoryItemsRemovedNotification`](/documentation/WebKit/WebHistoryItemsRemovedNotification)

Posted when items have been removed from the web history.

[`WebHistoryLoadedNotification`](/documentation/WebKit/WebHistoryLoadedNotification)

Posted when web history items have been loaded from a URL.

[`WebHistorySavedNotification`](/documentation/WebKit/WebHistorySavedNotification)

Posted when web history items have been saved to a URL.

### Notifications

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/WebHistoryAllItemsRemoved>

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/WebHistoryItemChanged>

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/WebHistoryItemsAdded>

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/WebHistoryItemsRemoved>

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/WebHistoryLoaded>

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/WebHistorySaved>

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)