I am confused as I have created a MTLBuffer in Swift 4 yet am unable to use the method didModifyRange.
Interestingly enough I can still find this in the Apple documentation and have not heard of this being changed.
Why is the error Value of type 'MTLBuffer' has no member 'didModifyRange'
happening?
The following code would generate this error in the latest version of XCode
let device = MTLCreateSystemDefaultDevice()
var buffer = device?.makeBuffer(length: 3, options: [])
let range = Range<Int>(NSRange())
buffer.didModifyRange(range)
According to documentation, signature of the method looks like this:
func didModifyRange(_ range: Range<Int>)
You pass NSRange
which is obviously different from Swift Range<Int>
. So to get it work, simply pass proper range object.
P.S. Range<Int>
is defined with min...max
scheme (e.g. 0...100
).
EDIT:
Some Metal
framework signatures are only available on macOS 11.1, including didModifyRange:
, so if you try to call it on iOS, even having import Metal
in the header, will give you that error.
So the following code will compile under macOS 11.1
import Metal
// ...
guard
let device = MTLCreateSystemDefaultDevice(),
let buffer = device.makeBuffer(length: 3, options: [])
else {
return
}
buffer.didModifyRange(Range<Int>(1...10))
...and will not, under iOS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With