<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecAccessControlCreateWithFlags(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecAccessControlCreateWithFlags"
  },
  "title" : "SecAccessControlCreateWithFlags(_:_:_:_:)"
}
-->

# SecAccessControlCreateWithFlags(_:_:_:_:)

Creates a new access control object with the specified protection type and flags.

```
func SecAccessControlCreateWithFlags(_ allocator: CFAllocator?, _ protection: CFTypeRef, _ flags: SecAccessControlCreateFlags, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>?) -> SecAccessControl?
```

## Parameters

`allocator`

The allocator to use to allocate memory for the new [`SecAccessControl`](/documentation/Security/SecAccessControl) object. Pass `NULL` or <doc://com.apple.documentation/documentation/CoreFoundation/kCFAllocatorDefault> to allocate memory for the new allocator using the default allocator.

`protection`

Protection class to be used for the item. Use one of the values that go with the [`kSecAttrAccessible`](/documentation/Security/kSecAttrAccessible) attribute key, namely those listed in [Accessibility Values](/documentation/Security/item-attribute-keys-and-values#Accessibility-Values).

`flags`

Flags specifying the allowed operations for the item. See [`SecAccessControlCreateFlags`](/documentation/Security/SecAccessControlCreateFlags).

`error`

On return, if an error occurred, the reference pointed at by this parameter refers to an error object that indicates the reason for failure. The caller is responsible for releasing the error object. Pass `NULL` for this parameter to ignore the error.

## Return Value

The newly created access control object. In Objective-C, free this item with <doc://com.apple.documentation/documentation/CoreFoundation/CFRelease> when you are done with it.

## Discussion

You use the result of this function as a value for the [`kSecAttrAccessControl`](/documentation/Security/kSecAttrAccessControl) attribute in the [`SecItemAdd(_:_:)`](/documentation/Security/SecItemAdd(_:_:)), [`SecItemUpdate(_:_:)`](/documentation/Security/SecItemUpdate(_:_:)), or [`SecKeyGeneratePair(_:_:_:)`](/documentation/Security/SecKeyGeneratePair(_:_:_:)) functions.

Accessing keychain items or performing operations on keys that are protected by access control objects may block execution on the main thread. Perform these actions in the background, or use them in combination with the [`kSecUseAuthenticationContext`](/documentation/Security/kSecUseAuthenticationContext) and [`kSecUseAuthenticationUI`](/documentation/Security/kSecUseAuthenticationUI) attributes to manage user interactions.

---

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)