When I try to create new instance of AKFFTap in Objective-C, it claims that the init function is not available
This line gives me the error: "No visible @interface for 'AKFFTTap' declares the selector 'init:'"
AKFFTTap *tap = [[AKFFTTap alloc] init:_player]
This line gives me the error: "'init' is not available"
AKFFTTap *tap = [[AKFFTTap alloc] init];
How can I initialize it in Objective-C?
I'm using version 4.2.2
UPDATE:
AKFFTTap *tap = [[AKFFTTap alloc] initWithInput:_player];
Gives me the error; "No visible @interface for 'AKFFTTap' declares the selector 'initWithInput:'"
I'm importing the following in my header file
#import <AudioKit/AudioKit.h>
#import <AudioKit/AudioKit-Swift.h>
Figured it out
The init method in AKFFTTap.swift was missing the @objc
flag and so it's not revealed to Objective-C code
public init(_ input: AKNode, fftSize: AKSettings.BufferLength = .veryLong)
This results in AudioKit-Swift.h not having an init method that can be used for AKFFTTap
SWIFT_CLASS("_TtC8AudioKit8AKFFTTap")
@interface AKFFTTap : NSObject <EZAudioFFTDelegate>
/// Array of FFT data
@property (nonatomic, copy) NSArray<NSNumber *> * _Nonnull fftData;
- (void)fft:(EZAudioFFT * _Null_unspecified)fft updatedWithFFTData:(float * _Nonnull)fftData bufferSize:(vDSP_Length)bufferSize;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
+ (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
@end
I was able to fix this on my end by adding @objc
onto the Swift method, which then added the init method to AudioKit-Swift.h. I was able to successfully initialize the tap and get spectral data
In AKFFTTap.swift:
@objc public init(_ input: AKNode, fftSize: AKSettings.BufferLength = .veryLong)
After rebuilding the framework, resulted in this block of code in AudioKit-Swift.h:
SWIFT_CLASS("_TtC8AudioKit8AKFFTTap")
@interface AKFFTTap : NSObject <EZAudioFFTDelegate>
/// Array of FFT data
@property (nonatomic, copy) NSArray<NSNumber *> * _Nonnull fftData;
/// Initialze the FFT calculation on a given node
/// \param input Node on whose output the FFT will be computed
///
/// \param fftSize The sample size of the FFT buffer
///
- (nonnull instancetype)init:(AKNode * _Nonnull)input fftSize:(enum BufferLength)fftSize OBJC_DESIGNATED_INITIALIZER;
- (void)fft:(EZAudioFFT * _Null_unspecified)fft updatedWithFFTData:(float * _Nonnull)fftData bufferSize:(vDSP_Length)bufferSize;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
+ (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
@end