I would like to avoid importing AVFoundation
framework in my header but I need to declare CMTime
.
For NSObject
I can do @class AVPlayer;
and import everything in the .m file. How to do this with a struct like CMTime
?
If you need to reference CMTime
struct in the header, you need to include <CMTime.h>
: forward-declaring a struct
lets you use the name of the type in declarations of pointers, but not in declarations of members of that struct type.
In other words, you can do this:
struct CMTime; // Forward declaration of the struct
@interface MyInterface : NSObject
-(void)fillCmTime:(CMTime*)buffer;
@end
but you cannot do this:
struct CMTime; // Forward declaration of the struct
@interface MyInterface : NSObject {
// This is not allowed
CMTime time;
}
// This is not allowed either
-(CMTime)getTime;
@end
The reason that you can do @class AVPlayer
and then use it in declarations of members is that Objective-C classes (id
-types) are implemented as pointers. In fact, you cannot declare variables of an id
-type without an asterisk.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments