1

I got Xcode warning :

"'withUnsafeBytes' is deprecated: use withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R instead"

The code is :

_document = data.withUnsafeBytes({ (p: UnsafePointer<Int8>) -> htmlDocPtr? in
                return htmlReadMemory(p, Int32(data.count), nil, nil, 0)
            }) 

 

I'm more objective-c guy, and I stumble for 1 hour to shutdown this warning but no luck Any ideas ?

I already checked this answer : Swift 5.0: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(...)

EDIT: Also checked this and got the same warning :
https://github.com/leonbreedt/FavIcon/issues/23#issue-365477776

Frakcool
  • 10,915
  • 9
  • 50
  • 89
user1105951
  • 2,259
  • 2
  • 34
  • 55
  • 1
    This is not reproduced (Change your code with this) : https://github.com/leonbreedt/FavIcon/blob/e3bac1dc271feffba3bc38777e1a2d97d9af7ae7/Sources/FavIcon/HTML.swift#L34 – Raja Kishan May 31 '21 at 15:38
  • Bingo. Thank you very much ! Can you answer in the right place so I will mark it is solved ? – user1105951 May 31 '21 at 16:42
  • *I already checked this answer*. The `baseAddress.assumingMemoryBound` solution is being suggested in the answer (which I marked as duplicate in your first, deleted question by the way). – vadian May 31 '21 at 17:09

1 Answers1

2

As per the in the doc

you can change with this

_document = data.withUnsafeBytes { ptr in
    htmlReadMemory(ptr.baseAddress?.assumingMemoryBound(to: Int8.self), Int32(data.count), nil, nil, 0)
}
Raja Kishan
  • 16,767
  • 2
  • 26
  • 52