I have a typedef as so:
typedef NSString VMVideoCategoryType;
extern VMVideoCategoryType *const VMVideoCategoryType_MusicVideo;
extern VMVideoCategoryType *const VMVideoCategoryType_Audio;
extern VMVideoCategoryType *const VMVideoCategoryType_Performance;
extern VMVideoCategoryType *const VMVideoCategoryType_Lyric;
extern VMVideoCategoryType *const VMVideoCategoryType_Show;
I've included this file in the bridging header. However, when I try to access VMVideoCategoryType
in a Swift file I get an error:
Use of undeclared type 'VMVideoCategoryType'
Is there any way to make this work or do I have to completely re-define this type in Swift?
I am a little bit speculating, but the reason seems to be that Objective-C
objects like NSString
cannot be statically allocated (see e.g. Are objects in Objective-C ever created on the stack?). If
typedef NSString VMVideoCategoryType;
were imported into Swift then you could declare a local variable
var foo : VMVideoCategoryType
which would be a NSString
and not a pointer to NSString
.
Note also that what you see in Swift as NSString
corresponds to NSString *
in Objective-C.
If you define VMVideoCategoryType
as a typedef for NSString *
then it is visible in Swift:
typedef NSString * VMVideoCategoryType;
extern VMVideoCategoryType const VMVideoCategoryType_MusicVideo;
// ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With