Wrapping a C creation method that returns object by reference?

There is a workaround for this in the general case:

protocol SelfAssignableInit {
    init(assigningFrom other: Self)
}

extension SelfAssignableInit {
    init(assigningFrom other: Self) {
        self = other
    }
}

extension CVPixelBuffer: SelfAssignableInit {}

https://forums.swift.org/t/allow-self-x-in-class-convenience-initializers/ from a few years back gives more details/discussion.

In this particular case, however, you may have another issue: I don't think you can write convenience inits for CoreFoundation types, and I think that includes CVPixelBuffer. At a guess, that's what you're running into for your first issue.

4 Likes