Reputation: 3837
This is highly related to other questions about accessing ObjC callbacks from Swift. But my research is yet to not yield working results.
Anyone able to see if I am possibly doing something wrong syntax wise here?
I've declare the following Objective-C callback as:
#import <UIKit/UIKit.h>
@class KxMovieDecoder;
typedef void (^KX_FIRST_FRAME_CALLBACK)() ;
extern NSString * const KxMovieParameterMinBufferedDuration; // Float
extern NSString * const KxMovieParameterMaxBufferedDuration; // Float
extern NSString * const KxMovieParameterDisableDeinterlacing; // BOOL
@interface KxMovieViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> {
KX_FIRST_FRAME_CALLBACK firstFrameLoaded;
}
+ (id) movieViewControllerWithContentPath: (NSString *) path
parameters: (NSDictionary *) parameters;
@property (readonly) BOOL playing;
@property (nonatomic, copy) KX_FIRST_FRAME_CALLBACK firstFrameLoaded;
- (void) play;
- (void) pause;
@end
When I assign to it from swift code, it is still nil after assignment:
public func startViewing() -> UIViewController {
kxMoviePlayer = KxMovieViewController.movieViewControllerWithContentPath(rtspURL, parameters: nil) as? KxMovieViewController
kxMoviePlayer!.firstFrameLoaded = {
self.onFirstFrameOfVideo()
}
Upvotes: 0
Views: 283
Reputation: 1529
Just put together a blank project with a similar set up and it worked fine. A couple of questions though.
Did you mean to have both an instance variable and a property named firstFrameLoaded
? Your auto-synthesized property is not using the instance variable and is instead using an auto-generated _firstFrameLoaded
instance variable. Perhaps this is the source of the confusion and you meant to prefix the i-var with an underscore?
Any reason the callback property is a copy
instead of indicating strong
or weak
referencing?
Upvotes: 1