1

转发声明Objective C 类很容易。

@class ClassWhoseHeaderNotYetImported;

但是,此策略不适用于 CoreFoundation 类型CVImageBufferRef或任何继承自CFTypeRef. 在目标 C 中转发声明 CoreFoundation 类型的正确方法是什么?

4

1 回答 1

1

@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.

于 2013-11-01T04:15:13.170 回答