Domanda

It's easy to forward declare Objective C classes.

@class ClassWhoseHeaderNotYetImported;

However, this strategy doesn't work with CoreFoundation types like CVImageBufferRef or anything that inherits from CFTypeRef. What's the right way to forward declare CoreFoundation types in objective C?

È stato utile?

Soluzione

@class doesn't work for Core Foundation types because they're not classes, they're structs, e.g. if you look at the definition of CVImageBufferRef you see this:

typedef struct __CVBuffer *CVBufferRef;
...
typedef CVBufferRef CVImageBufferRef;

So in order to forward-declare a CF type, you need to know what the underlying struct is. You can look it up in Xcode fairly easily with ⌘-click. If there are multiple levels, as here, you don't need to declare all of them (unless you need to use the intermediates). The following should work

typedef struct __CVBuffer *CVImageBufferRef;

If you really can't be bothered to look up the types, you could probably get away with void *. It's technically not safe, but it will never fail on iOS or OSX unless Apple seriously f-s stuff up.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top