Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value of type 'MTLBuffer' has no member 'didModifyRange'

Tags:

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)
like image 421
J.Doe Avatar asked Dec 21 '17 05:12

J.Doe


1 Answers

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.

like image 53
Hexfire Avatar answered Nov 15 '22 05:11

Hexfire