Can't call some functions in an ObjC category from Swift. Keep getting "Value type has no member" or "Cannot find in scope" errors.

Aargh. I have a category written in Objective-C that adds an equalizer to AVPlayer. I downloaded it from https://github.com/akhilcb/ACBAVPlayerExtension and dragged the relevant source files into my project. I'm sure the target memberships of them are correct.

The .H file for the ObjC category starts off like this:
Code Block
@interface AVPlayer(ACBHelper)
- (void)fooTest;
@property (nonatomic, getter=isMeteringEnabled) BOOL meteringEnabled; /* turns level metering on or off. default is off. */


My bridging header .H file definitely has the #import statements to include the category, and I know it's being used because if I put a syntax error in there as a test, I get an error.

I cannot get past this error in my code:
Code Block
"Value of type 'AVPlayer' has no member 'isMeteringEnabled"

with these lines:
Code Block
self.player = AVPlayer(playerItem: playerItem)
self.player.meteringEnabled = true

I tried using meteringEnabled and isMeteringEnabled with no success.

As an experiment, I added fooTest() to the category just to see if I can call it. I try to call it like this from Swift:
Code Block
self.player.fooTest()

I keep getting an error "Value of type AVPlayer has no member fooTest which is nonsense. fooTest shows up in autocomplete.

Also, if I right-click on fooTest in the line that says self.player.foohTest(), and select Jump to Definition, I am taken to the .H file and the line where I added
- (void)fooTest;
As far as I tried, the GitHub repository you have referred lacks the right definition of protocol MYAudioTabProcessorDelegate and does not compile.

Are you sure you have fixed the issue and your project compiles successfully when you remove self.player.meteringEnabled = true (and all other self.player.... parts causing the error)?
Yes, my project compiles OK for me if I remove those lines that try calling fooTest() or try setting self.player.meteringEnabled

The Github project compiles ok for me too. All I did was drag these 6 files into my project:
Code Block
ACBAudioProcessHelper.h
ACBAudioProcessHelper.m
AVPlayer+ACBHelper.h   
AVPlayer+ACBHelper.m   
MYAudioTapProcessor.h  
MYAudioTapProcessor.m


Here's the entire contents of my bridging header.h file:
Code Block
#import "AVPlayer+ACBHelper.h"
#import "ACBAudioProcessHelper.h"
#import "MyAudioTapProcessor.h"


I'm totally sure those files are being used because if I put a syntax error in those files (on purpose), I get an error.

I was able to download that Github thing by getting the master branch, opening ACBAVPlayerExtension.xcodeproj and building it by choosing the ACBAVPlayerExtension target and a simulator. I think I had to assign a team under the Signing and Capabilities section, but it builds ok using Xcode 12.4 and Big Sur.

I've spent probably 3-4 hours on this problem. Will spend another hour or 2 tonight but I'm really stuck. Wish I could post screen shots here.

Yes, my project compiles OK for me if I remove those lines that try calling fooTest() or try setting self.player.meteringEnabled

Thanks for your reply. Then the issue may be different than I guessed.

The Github project compiles ok

It does not have any meaning if the original ObjC only project would compile or not.
I think I fixed this. I think the problem is because I have multiple targets in my project (iOS, tvOS, watchOS, etc) and that the watchOS project is not using my bridging header. I was getting compiler errors because I didn't realize my Swift files were being compiled for the iOS, and the watch. By making the watch target use the bridging header, that seems to help a lot.
Can't call some functions in an ObjC category from Swift. Keep getting "Value type has no member" or "Cannot find in scope" errors.
 
 
Q