Question: I am taking a screenshot of a WKVebView in the completion handler of a javascript evaluation:

```
func loadPage(){
    let fileURL = URL(fileURLWithPath: "...")
    let baseUrl = URL(fileURLWithPath: "...")
    webView?.navigationDelegate = self
    webView.loadFileURL(fileURL, allowingReadAccessTo: baseUrl)
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    webView.evaluateJavaScript("....") { (result, error) in
        let configuration = WKSnapshotConfiguration()
        configuration.rect = CGRect(origin: .zero, size: (self.webView?.frame.size)!)
        self.webView!.takeSnapshot(with: configuration, completionHandler: { (image, error) in
            // do something with the image
        })
}

```

Even if it is in the completion handler of the `webView.evaluateJavaScript` function, the content if often not finished to render and I am getting either blank screenshot or partial ones (only some elements are present).

How can I ensure that rendering is completed before taking screenshot (I do not want to introduce fixed delay)

Answer: 
You have to change the closure argument to `UnsafeRawBufferPointer` and then take its `baseAdress` (which is a `UnsafeRawPointer?`, the Swift equivalent of `void *` in C):

```
data.withUnsafeBytes( { (ptr : UnsafeRawBufferPointer) in
    let value = readFITfile(ptr.baseAddress)
    // ...
})

```

The Swift compiler can also infer the closure argument type automatically:

```
data.withUnsafeBytes( { ptr in
    let value = readFITfile(ptr.baseAddress)
    // ...
})

```

For more information about this problem, see [withUnsafeBytes Data API confusion](https://forums.swift.org/t/withunsafebytes-data-api-confusion/22142) in the Swift forum.
To get UnsafePointer now you should do something like that

```
data.withUnsafeBytes { (ptr: UnsafeRawBufferPointer) in
    if let ptrAddress = ptr.baseAddress, ptr.count > 0 {
        let pointer = ptrAddress.assumingMemoryBound(to: UInt8.self) // here you got UnsafePointer<UInt8>
        let value = readFITfile(ptr)
        print( value )
    } else {
        // Here you should provide some error handling if you want ofc
    }
}

```