简体   繁体   English

Objective-C应用程序中缺少Swift框架中的IBOutlet属性

[英]IBOutlet properties from Swift framework are missing from Objective-C app

I have a framework I've written in Swift that contains a class that extends UIView and that has an IBOutlet property. 我有一个我在Swift中编写的框架,它包含一个扩展UIView并具有IBOutlet属性的类。

The class is visible from my Objective-C app, but Interface Builder won't see the IBOutlet. 从我的Objective-C应用程序可以看到该类,但Interface Builder将看不到IBOutlet。 Here's the code: 这是代码:

@objc protocol MyFrameworkDelegate {
    // My delegate methods here
    ...
}

@objc class MyFrameworkClass: UIView {

    @objc @IBOutlet var delegate:MyFrameworkDelegate?
    // The rest of my class here
    ...
}

I set my view's class to MyFrameworkClass in my storyboard, but the delegate outlet isn't showing. 我把我的观点的上课MyFrameworkClass在我的故事板,但delegate出口没有显示。

I tried with and without the @objc modifier, no luck. 我尝试使用和不使用@objc修饰符,没有运气。 When I inspect my class from Objective-C, the property comes up without the IBOutlet . 当我从Objective-C检查我的类时,该属性在没有IBOutlet情况下出现。

Anyone else came across something like that? 还有其他人遇到过类似的东西吗?

EDIT 编辑

Here's the code generated by Xcode for the Swift -> Objective-C conversion: 这是Xcode为Swift生成的代码 - > Objective-C转换:

@protocol MyFrameworkDelegate;

SWIFT_CLASS("_Nc9a0xD6MyFrameworkClass")
@interface MyFrameworkClass : UIView
@property (nonatomic) id <MyFrameworkDelegate> delegate;
...

Also, here's the error message I get when I try to run the app: 此外,这是我尝试运行应用程序时收到的错误消息:

2014-06-22 21:41:59.095 MyApp Test[75211:17812266] Unknown class MyFrameworkClass in Interface Builder file.
2014-06-22 21:41:59.099 MyApp Test[75211:17812266] -[UIView setDelegate:]: unrecognized selector sent to instance 0xcf5d650
2014-06-22 21:41:59.101 MyApp Test[75211:17812266] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setDelegate:]: unrecognized selector sent to instance 0xcf5d650'

EDIT 编辑

Here's a screenshot of my storyboard: 这是我的故事板的截图:

在此输入图像描述

您的模块为“ None ,您应该将其选择为相应的值。

reason: '-[UIView setDelegate:]: unrecognized selector

This makes it look like the object in question is an instance of UIView , not MyFrameworkClass . 这使得看起来有问题的对象是UIView的实例,而不是MyFrameworkClass Check the type of the object in IB. 检查IB中对象的类型。

I suspect the word delegate itself is triggering some kind of underlying bug/mechanism/leaky abstraction. 我怀疑委托本身这个词正在触发某种潜在的错误/机制/漏洞抽象。

How about calling it myFrameworkDelegate? 如何称它为myFrameworkDelegate?

I am also wondering if dragging from IB shouldn't always give the best results by itself but I need to fire up Xcode 6 and test manually first to see what happens. 我也想知道从IB拖出是不是总能给出最好的结果,但我需要启动Xcode 6并首先手动测试以查看会发生什么。 New technology :) 新技术 :)

Instead of 代替

@objc @IBOutlet var delegate:MyFrameworkDelegate?

use 采用

@IBOutlet var delegate:AnyObject?

than you'll be able to link your class to this property. 你可以将你的班级链接到这个属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM