<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSIncrementalStore/newValue(forRelationship:forObjectWith:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSIncrementalStore(im)newValueForRelationship:forObjectWithID:withContext:error:"
  },
  "title" : "newValue(forRelationship:forObjectWith:with:)"
}
-->

# newValue(forRelationship:forObjectWith:with:)

Returns the relationship for the given relationship of the object with a given object ID.

```
func newValue(forRelationship relationship: NSRelationshipDescription, forObjectWith objectID: NSManagedObjectID, with context: NSManagedObjectContext?) throws -> Any
```

## Parameters

`relationship`

The relationship for which values are requested.

`objectID`

The ID of the object for which values are requested.

`context`

The managed object context into which values will be returned.

## Return Value

The value of the relationship specified `relationship` of the object with object ID `objectID`, or `nil` if an error occurs.

## Discussion

If the relationship is a to-one, the method should return an [`NSManagedObjectID`](/documentation/CoreData/NSManagedObjectID) instance that identifies the destination, or an instance of <doc://com.apple.documentation/documentation/Foundation/NSNull> if the relationship value is `nil`.

If the relationship is a to-many, the method should return a collection object containing [`NSManagedObjectID`](/documentation/CoreData/NSManagedObjectID) instances to identify the related objects. Using an `NSArray` instance is preferred because it will be the most efficient. A store may also return an instance of `NSSet` or `NSOrderedSet`; an instance of `NSDictionary` is not acceptable.

If an object with object ID `objectID` cannot be found, the method should return `nil` and—if `error` is not `NULL`—create and return an appropriate error object in `error`.

---

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)