<!--
{
  "availability" : [
    "macOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Virtualization",
  "identifier" : "/documentation/Virtualization/VZVirtioQueue/nextElement()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Virtualization"
    ],
    "preciseIdentifier" : "c:objc(cs)VZVirtioQueue(im)nextElement"
  },
  "title" : "nextElement()"
}
-->

# nextElement()

Gets the next element in this queue, if any.

```
func nextElement() -> VZVirtioQueueElement?
```

## Return Value

The next available element on this queue, or `nil` if no elements are available or if the device is no longer live.

## Discussion

Use this method to obtain any elements (available buffers), that the Virtualization framework represents as `VZVirtioQueueElement`,
in the virtqueue for processing.

You need to call the [`returnToQueue()`](/documentation/Virtualization/VZVirtioQueueElement/returnToQueue()) method when you are finished processing the element in order
to return the element back to the guest.

When using this method, the framework disables virtqueue notifications until you have consumed every available element. When calling
this method in response to a virtqueue notification, you need to do so repeatedly until it returns `nil` (which indicates there are no more
elements available in the queue), typically in a loop like this:

```swift
    let queue: VZVirtioQueue = ...
    while let element = queue.nextElement() {
        // Code to process the element.
}
```

---

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)