Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法符合objective-c中的swift委托协议_Ios_Objective C_Swift_Protocols - Fatal编程技术网

Ios 无法符合objective-c中的swift委托协议

Ios 无法符合objective-c中的swift委托协议,ios,objective-c,swift,protocols,Ios,Objective C,Swift,Protocols,我正在一个objective C项目中使用swift pod。 我成功地从objective-c访问了swift类,无论如何,我面临着采用swift协议的问题。 编译器没有抱怨,生成的桥接头似乎正确 调用[self.sceneLocationView setLocationNodeTouchDelegate:self]时在运行时出现问题:发送到实例的选择器无法识别 我找不到这个问题的任何解决方案,我花了时间在这里搜索,但仍然没有成功。 任何帮助都将不胜感激。 谢谢 我的swift和objecti

我正在一个objective C项目中使用swift pod。
我成功地从objective-c访问了swift类,无论如何,我面临着采用swift协议的问题。
编译器没有抱怨,生成的桥接头似乎正确

调用
[self.sceneLocationView setLocationNodeTouchDelegate:self]时在运行时出现问题[ARCL.SceneLocationView setLocationNodeTouchDelegate:]的代码>:发送到实例的选择器无法识别

我找不到这个问题的任何解决方案,我花了时间在这里搜索,但仍然没有成功。
任何帮助都将不胜感激。
谢谢

我的swift和objective-c文件如下所示

SceneLocationView.swift:

@available(iOS 11.0, *)
open class SceneLocationView: ARSCNView {
   ...
   @objc public weak var locationNodeTouchDelegate: LNTouchDelegate?
   ...
}
@objc public protocol LNTouchDelegate: class {
    func locationNodeTouched(node: AnnotationNode)
}
#import "ARCL-Swift.h"

@interface ViewController : UIViewController <LNTouchDelegate>{
}

@property (nonatomic, strong) SceneLocationView *sceneLocationView;

#import "ARCL-Swift.h"
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sceneLocationView = [[SceneLocationView alloc] init];
    [self.sceneLocationView run];
    [self.view addSubview: self.sceneLocationView];
    ...
    [self.sceneLocationView setLocationNodeTouchDelegate: self]; <-- ERROR HERE
}

-(void) locationNodeTouchedWithNode:(AnnotationNode *)node {
}
SWIFT_PROTOCOL("_TtP4ARCL15LNTouchDelegate_")
@protocol LNTouchDelegate
- (void)locationNodeTouchedWithNode:(AnnotationNode * _Nonnull)node;
@end

SWIFT_CLASS("_TtC4ARCL17SceneLocationView") SWIFT_AVAILABILITY(ios,introduced=11.0)
@interface SceneLocationView : ARSCNView
@property (nonatomic, weak) id <LNTouchDelegate> _Nullable locationNodeTouchDelegate;
- (nonnull instancetype)init;
- (nonnull instancetype)initWithFrame:(CGRect)frame options:(NSDictionary<NSString *, id> * _Nullable)options OBJC_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder * _Nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
- (void)layoutSubviews;
- (nonnull instancetype)initWithFrame:(CGRect)frame SWIFT_UNAVAILABLE;
@end
SceneLocationViewDelegate.swift:

@available(iOS 11.0, *)
open class SceneLocationView: ARSCNView {
   ...
   @objc public weak var locationNodeTouchDelegate: LNTouchDelegate?
   ...
}
@objc public protocol LNTouchDelegate: class {
    func locationNodeTouched(node: AnnotationNode)
}
#import "ARCL-Swift.h"

@interface ViewController : UIViewController <LNTouchDelegate>{
}

@property (nonatomic, strong) SceneLocationView *sceneLocationView;

#import "ARCL-Swift.h"
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sceneLocationView = [[SceneLocationView alloc] init];
    [self.sceneLocationView run];
    [self.view addSubview: self.sceneLocationView];
    ...
    [self.sceneLocationView setLocationNodeTouchDelegate: self]; <-- ERROR HERE
}

-(void) locationNodeTouchedWithNode:(AnnotationNode *)node {
}
SWIFT_PROTOCOL("_TtP4ARCL15LNTouchDelegate_")
@protocol LNTouchDelegate
- (void)locationNodeTouchedWithNode:(AnnotationNode * _Nonnull)node;
@end

SWIFT_CLASS("_TtC4ARCL17SceneLocationView") SWIFT_AVAILABILITY(ios,introduced=11.0)
@interface SceneLocationView : ARSCNView
@property (nonatomic, weak) id <LNTouchDelegate> _Nullable locationNodeTouchDelegate;
- (nonnull instancetype)init;
- (nonnull instancetype)initWithFrame:(CGRect)frame options:(NSDictionary<NSString *, id> * _Nullable)options OBJC_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder * _Nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
- (void)layoutSubviews;
- (nonnull instancetype)initWithFrame:(CGRect)frame SWIFT_UNAVAILABLE;
@end
ViewController.h:

@available(iOS 11.0, *)
open class SceneLocationView: ARSCNView {
   ...
   @objc public weak var locationNodeTouchDelegate: LNTouchDelegate?
   ...
}
@objc public protocol LNTouchDelegate: class {
    func locationNodeTouched(node: AnnotationNode)
}
#import "ARCL-Swift.h"

@interface ViewController : UIViewController <LNTouchDelegate>{
}

@property (nonatomic, strong) SceneLocationView *sceneLocationView;

#import "ARCL-Swift.h"
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sceneLocationView = [[SceneLocationView alloc] init];
    [self.sceneLocationView run];
    [self.view addSubview: self.sceneLocationView];
    ...
    [self.sceneLocationView setLocationNodeTouchDelegate: self]; <-- ERROR HERE
}

-(void) locationNodeTouchedWithNode:(AnnotationNode *)node {
}
SWIFT_PROTOCOL("_TtP4ARCL15LNTouchDelegate_")
@protocol LNTouchDelegate
- (void)locationNodeTouchedWithNode:(AnnotationNode * _Nonnull)node;
@end

SWIFT_CLASS("_TtC4ARCL17SceneLocationView") SWIFT_AVAILABILITY(ios,introduced=11.0)
@interface SceneLocationView : ARSCNView
@property (nonatomic, weak) id <LNTouchDelegate> _Nullable locationNodeTouchDelegate;
- (nonnull instancetype)init;
- (nonnull instancetype)initWithFrame:(CGRect)frame options:(NSDictionary<NSString *, id> * _Nullable)options OBJC_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder * _Nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
- (void)layoutSubviews;
- (nonnull instancetype)initWithFrame:(CGRect)frame SWIFT_UNAVAILABLE;
@end
#导入“ARCL Swift.h”
@界面ViewController:UIViewController{
}
@属性(非原子,强)SceneLocationView*SceneLocationView;
ViewController.m:

@available(iOS 11.0, *)
open class SceneLocationView: ARSCNView {
   ...
   @objc public weak var locationNodeTouchDelegate: LNTouchDelegate?
   ...
}
@objc public protocol LNTouchDelegate: class {
    func locationNodeTouched(node: AnnotationNode)
}
#import "ARCL-Swift.h"

@interface ViewController : UIViewController <LNTouchDelegate>{
}

@property (nonatomic, strong) SceneLocationView *sceneLocationView;

#import "ARCL-Swift.h"
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sceneLocationView = [[SceneLocationView alloc] init];
    [self.sceneLocationView run];
    [self.view addSubview: self.sceneLocationView];
    ...
    [self.sceneLocationView setLocationNodeTouchDelegate: self]; <-- ERROR HERE
}

-(void) locationNodeTouchedWithNode:(AnnotationNode *)node {
}
SWIFT_PROTOCOL("_TtP4ARCL15LNTouchDelegate_")
@protocol LNTouchDelegate
- (void)locationNodeTouchedWithNode:(AnnotationNode * _Nonnull)node;
@end

SWIFT_CLASS("_TtC4ARCL17SceneLocationView") SWIFT_AVAILABILITY(ios,introduced=11.0)
@interface SceneLocationView : ARSCNView
@property (nonatomic, weak) id <LNTouchDelegate> _Nullable locationNodeTouchDelegate;
- (nonnull instancetype)init;
- (nonnull instancetype)initWithFrame:(CGRect)frame options:(NSDictionary<NSString *, id> * _Nullable)options OBJC_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder * _Nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
- (void)layoutSubviews;
- (nonnull instancetype)initWithFrame:(CGRect)frame SWIFT_UNAVAILABLE;
@end
#导入“ARCL Swift.h”
#导入“ViewController.h”
@实现视图控制器
-(无效)viewDidLoad{
[超级视图下载];
self.sceneLocationView=[[sceneLocationView alloc]init];
[self.sceneLocationView运行];
[self.view addSubview:self.sceneLocationView];
...

[self.sceneLocationView setLocationNodeTouchDelegate:self];如果您只使用简单赋值
self.sceneLocationView.locationNodeTouchDelegate=self;
,会发生什么情况?同样,这会导致相同的运行时错误。在这里工作。使用Xcode 11.2进行测试。我刚刚使用
sceneLocationView:UIView
进行测试。原因似乎不在提供的代码中。感谢您的测试@Asperi,我正在使用X代码10.2,因为我的mac太旧了,无法安装最新的Xcode 11。你使用了swift 5吗?Xcode要求我将swift 4.2转换为5Works,以及macOS 10.13.6/Xcode 9/swift 4.0。我没有这些版本。这可能是pod或项目配置中的原因,但Objective-C swift bridge肯定没有问题。