<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "swift: 5.9.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/Attribute(_:originalName:hashModifier:)",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData9Attribute_12originalName12hashModifieryAA6SchemaCABC6OptionVd_SSSgAJtcfm"
  },
  "title" : "Attribute(_:originalName:hashModifier:)"
}
-->

# Attribute(_:originalName:hashModifier:)

Specifies the custom behavior that SwiftData applies to the annotated property
when managing the owning class.

```
@attached(peer) macro Attribute(_ options: Schema.Attribute.Option..., originalName: String? = nil, hashModifier: String? = nil)
```

## Parameters

`options`

A list of options to apply to the attached property to customize its behavior. For possible values, see [`Schema.Attribute.Option`](/documentation/SwiftData/Schema/Attribute/Option).

`originalName`

The previous name of the attribute, if it’s different to the one in the current schema version. The default value is `nil`.

`hashModifier`

A unique hash value that represents the most recent version of the attached property. The default value is `nil`.

## Overview

The framework’s default behavior for managing a model class’s stored properties
is suitable for most use cases. However, if you need to alter the persistence
behavior of a particular property, annotate it with the `@Attribute` macro. For
example, you may want to avoid conflicts in your model data by specifying that
an attribute’s value is unique across all instances of that model.

```swift
@Model
class RemoteImage {
    @Attribute(.unique) var sourceURL: URL
    var data: Data
    
    init(sourceURL: URL, data: Data = Data()) {
        self.sourceURL = sourceURL
        self.data = data
    }
}
```

---

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)