Using obj-c typedef in Swift

I have a typedef like this:

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 have included this file in the header of the bridge. However, when I try to access VMVideoCategoryType in a Swift file, I get an error:

Use of undeclared type 'VMVideoCategoryType'

Is there a way to make this work, or do I need to completely override this type in Swift?

+6
source share
1 answer

I'm thinking a bit, but the reason is that Objective-C objects of type NSString cannot be statically distributed (see, for example, Are Objects Created in Objective-C on the Stack? ). If

 typedef NSString VMVideoCategoryType; 

were imported into Swift, then you could declare a local variable

 var foo : VMVideoCategoryType 

which would be NSString , 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 this can be seen in Swift:

 typedef NSString * VMVideoCategoryType; extern VMVideoCategoryType const VMVideoCategoryType_MusicVideo; // ... 
+9
source

Source: https://habr.com/ru/post/989973/


All Articles