<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSManagedObject/awakeFromInsert()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSManagedObject(im)awakeFromInsert"
  },
  "title" : "awakeFromInsert()"
}
-->

# awakeFromInsert()

Provides an opportunity to add code into the life cycle of the managed object when initially creating it.

```
func awakeFromInsert()
```

## Discussion

You typically use this method to initialize special default property values. This method is invoked only once in the object’s lifetime.

If you want to set attribute values in an implementation of this method, you should typically use primitive accessor methods (either [`setPrimitiveValue(_:forKey:)`](/documentation/CoreData/NSManagedObject/setPrimitiveValue(_:forKey:)) or—better—the appropriate custom primitive accessors). This ensures that the new values are treated as baseline values rather than being recorded as undoable changes for the properties in question.

> Important:
> Subclasses must invoke super’s implementation before performing their own initialization.

### Special Considerations

If you create a managed object then perform undo operations to bring the managed object context to a state prior to the object’s creation, then perform redo operations to bring the managed object context back to a state after the object’s creation, [`awakeFromInsert()`](/documentation/CoreData/NSManagedObject/awakeFromInsert()) is *not* invoked a second time.

You are typically discouraged from performing fetches within an implementation of [`awakeFromInsert()`](/documentation/CoreData/NSManagedObject/awakeFromInsert()). Although it is allowed, execution of the fetch request can trigger the sending of internal Core Data notifications which may have unwanted side-effects. For example, in macOS, an instance of <doc://com.apple.documentation/documentation/AppKit/NSArrayController> may end up inserting a new object into its content array twice.

---

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)