Ios 从Swift调用目标C方法
我正在Swift中构建一个应用程序,该应用程序导入一些.h文件。我有以下定义: RTCEAGLVideoView.hIos 从Swift调用目标C方法,ios,objective-c,swift,xcode,Ios,Objective C,Swift,Xcode,我正在Swift中构建一个应用程序,该应用程序导入一些.h文件。我有以下定义: RTCEAGLVideoView.h @interface RTCEAGLVideoView : UIView <RTCVideoRenderer> @property(nonatomic, weak) id<RTCEAGLVideoViewDelegate> delegate; @end 但我得到了一个错误: Value of type 'RTCVideoRenderer' ha
@interface RTCEAGLVideoView : UIView <RTCVideoRenderer>
@property(nonatomic, weak) id<RTCEAGLVideoViewDelegate> delegate;
@end
但我得到了一个错误:
Value of type 'RTCVideoRenderer' has no member 'renderFrame'
任何帮助都将不胜感激
编辑:
RTCI420Frame.h
#import <Foundation/Foundation.h>
// RTCI420Frame is an ObjectiveC version of cricket::VideoFrame.
@interface RTCI420Frame : NSObject
@property(nonatomic, readonly) NSUInteger width;
@property(nonatomic, readonly) NSUInteger height;
@property(nonatomic, readonly) NSUInteger chromaWidth;
@property(nonatomic, readonly) NSUInteger chromaHeight;
@property(nonatomic, readonly) NSUInteger chromaSize;
// These can return NULL if the object is not backed by a buffer.
@property(nonatomic, readonly) const uint8_t* yPlane;
@property(nonatomic, readonly) const uint8_t* uPlane;
@property(nonatomic, readonly) const uint8_t* vPlane;
@property(nonatomic, readonly) NSInteger yPitch;
@property(nonatomic, readonly) NSInteger uPitch;
@property(nonatomic, readonly) NSInteger vPitch;
- (BOOL)makeExclusive;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// Disallow init and don't add to documentation
- (id)init __attribute__((
unavailable("init is not a supported initializer for this class.")));
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
@end
#导入
//RTCI420Frame是cricket::VideoFrame的ObjectiveC版本。
@接口RTCI420Frame:NSObject
@属性(非原子,只读)为整数宽度;
@属性(非原子,只读)为整数高度;
@属性(非原子,只读)为整数色度宽度;
@属性(非原子,只读)为整数色度;
@属性(非原子,只读)为整数色度;
//如果对象不受缓冲区的支持,则它们可能返回NULL。
@属性(非原子,只读)constuint8_*t*yPlane;
@属性(非原子,只读)常量uint8_t*uPlane;
@属性(非原子,只读)常量uint8_t*vPlane;
@属性(非原子,只读)NSInteger-yPitch;
@属性(非原子,只读)NSInteger uPitch;
@属性(非原子,只读)NSInteger vPitch;
-(BOOL)makeExclusive;
#如果没有脱氧剂,则应跳过此步骤
//不允许初始化,不向文档中添加
-(id)init\uuu属性__((
不可用(“init不是该类支持的初始值设定项。”);
#endif/*DOXYGEN\u应跳过此步骤*/
@结束
我试图复制您的问题,但使用虚拟文件对我来说效果很好。我怀疑您的问题不是桥接所有依赖的头
以下是适用于我的文件:
RTCEAGLVideoView.h
----
#import <UIKit/UIKit.h>
#import "RTCEAGLVideoViewDelegate.h"
#import "RTCEAGLVideoView.h"
#import "RTCVideoRenderer.h"
@interface RTCEAGLVideoView : UIView <RTCVideoRenderer>
@property(nonatomic, weak) id<RTCEAGLVideoViewDelegate> delegate;
@end
RTCEAGLVideoView.m
----
#import "RTCEAGLVideoView.h"
@implementation RTCEAGLVideoView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (void)renderFrame:(RTCI420Frame*)frame {
NSLog(@"Render frame was called");
}
- (void)setSize:(CGSize)size {
NSLog(@"Size set");
}
@end
RTCEAGLVideoViewDelegate.h
----
#import <Foundation/Foundation.h>
@protocol RTCEAGLVideoViewDelegate <NSObject>
@end
RTCI420Frame.h
----
#import <Foundation/Foundation.h>
@interface RTCI420Frame : NSObject
@end
RTCI420Frame.m
----
#import "RTCI420Frame.h"
@implementation RTCI420Frame
@end
RTCVideoRenderer.h
----
#import <Foundation/Foundation.h>
#import "RTCI420Frame.h"
@protocol RTCVideoRenderer <NSObject>
// The size of the frame.
- (void)setSize:(CGSize)size;
// The frame to be displayed.
- (void)renderFrame:(RTCI420Frame*)frame;
@end
RenderThing-Bridging-Header.h
----
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import <UIKit/UIKit.h>
#import "RTCEAGLVideoViewDelegate.h"
#import "RTCEAGLVideoView.h"
#import "RTCVideoRenderer.h"
ViewController.swift
----
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var remoteView: RTCEAGLVideoView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.remoteView.renderFrame(nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
RTCEAGLVideoView.h
----
#进口
#导入“RTCEAGLVideoViewDelegate.h”
#导入“RTCEAGLVideoView.h”
#导入“RTCDeorenderer.h”
@接口RTCEAGLVideoView:UIView
@属性(非原子,弱)id委托;
@结束
RTCEAGLVideoView.m
----
#导入“RTCEAGLVideoView.h”
@RTCEAGLVideoView的实现
/*
//仅覆盖drawRect:如果执行自定义绘图。
//空实现会对动画期间的性能产生不利影响。
-(void)drawRect:(CGRect)rect{
//绘图代码
}
*/
-(无效)渲染帧:(RTCI420Frame*)帧{
NSLog(@“调用了渲染帧”);
}
-(无效)设置大小:(CGSize)大小{
NSLog(“尺寸集”);
}
@结束
RTCEAGLVideoViewDelegate.h
----
#进口
@协议RTCEAGLVideoViewDelegate
@结束
RTCI420Frame.h
----
#进口
@接口RTCI420Frame:NSObject
@结束
RTCI420Frame.m
----
#导入“RTCI420Frame.h”
@RTCI4200框架的实现
@结束
RTCVideoRenderer.h
----
#进口
#导入“RTCI420Frame.h”
@协议视频渲染器
//框架的大小。
-(无效)设置大小:(CGSize)大小;
//要显示的帧。
-(无效)渲染帧:(RTCI420Frame*)帧;
@结束
渲染桥接头.h
----
//
//使用此文件导入要向Swift公开的目标的公共标题。
//
#进口
#导入“RTCEAGLVideoViewDelegate.h”
#导入“RTCEAGLVideoView.h”
#导入“RTCDeorenderer.h”
ViewController.swift
----
导入UIKit
类ViewController:UIViewController{
@ibvar远程视图:RTCEAGLVideoView!
重写func viewDidLoad(){
super.viewDidLoad()
//加载视图后,通常从nib执行任何其他设置。
}
覆盖函数视图将出现(uo动画:Bool){
超级。视图将显示(动画)
self.remoteView.renderFrame(nil)
}
重写函数didReceiveMemoryWarning(){
超级。我收到了记忆警告()
//处置所有可以重新创建的资源。
}
}
请特别注意
呈现桥接头.h
文件中的差异您是否一直在使用桥接头?@EvgenyKarkan是的,我在其上添加了“RTCEAGLVideoView.h”。您是否也可以发布“RTCI420Frame”包含的内容?它可能会阻止该方法在swift中可用。@nickromano已完成。可能与的重复
#import <Foundation/Foundation.h>
// RTCI420Frame is an ObjectiveC version of cricket::VideoFrame.
@interface RTCI420Frame : NSObject
@property(nonatomic, readonly) NSUInteger width;
@property(nonatomic, readonly) NSUInteger height;
@property(nonatomic, readonly) NSUInteger chromaWidth;
@property(nonatomic, readonly) NSUInteger chromaHeight;
@property(nonatomic, readonly) NSUInteger chromaSize;
// These can return NULL if the object is not backed by a buffer.
@property(nonatomic, readonly) const uint8_t* yPlane;
@property(nonatomic, readonly) const uint8_t* uPlane;
@property(nonatomic, readonly) const uint8_t* vPlane;
@property(nonatomic, readonly) NSInteger yPitch;
@property(nonatomic, readonly) NSInteger uPitch;
@property(nonatomic, readonly) NSInteger vPitch;
- (BOOL)makeExclusive;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// Disallow init and don't add to documentation
- (id)init __attribute__((
unavailable("init is not a supported initializer for this class.")));
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
@end
RTCEAGLVideoView.h
----
#import <UIKit/UIKit.h>
#import "RTCEAGLVideoViewDelegate.h"
#import "RTCEAGLVideoView.h"
#import "RTCVideoRenderer.h"
@interface RTCEAGLVideoView : UIView <RTCVideoRenderer>
@property(nonatomic, weak) id<RTCEAGLVideoViewDelegate> delegate;
@end
RTCEAGLVideoView.m
----
#import "RTCEAGLVideoView.h"
@implementation RTCEAGLVideoView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (void)renderFrame:(RTCI420Frame*)frame {
NSLog(@"Render frame was called");
}
- (void)setSize:(CGSize)size {
NSLog(@"Size set");
}
@end
RTCEAGLVideoViewDelegate.h
----
#import <Foundation/Foundation.h>
@protocol RTCEAGLVideoViewDelegate <NSObject>
@end
RTCI420Frame.h
----
#import <Foundation/Foundation.h>
@interface RTCI420Frame : NSObject
@end
RTCI420Frame.m
----
#import "RTCI420Frame.h"
@implementation RTCI420Frame
@end
RTCVideoRenderer.h
----
#import <Foundation/Foundation.h>
#import "RTCI420Frame.h"
@protocol RTCVideoRenderer <NSObject>
// The size of the frame.
- (void)setSize:(CGSize)size;
// The frame to be displayed.
- (void)renderFrame:(RTCI420Frame*)frame;
@end
RenderThing-Bridging-Header.h
----
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import <UIKit/UIKit.h>
#import "RTCEAGLVideoViewDelegate.h"
#import "RTCEAGLVideoView.h"
#import "RTCVideoRenderer.h"
ViewController.swift
----
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var remoteView: RTCEAGLVideoView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.remoteView.renderFrame(nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}