OGeek|极客世界-中国程序员成长平台

标题: ios - 无法将 socket 连接到通用类 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:56
标题: ios - 无法将 socket 连接到通用类

xcode 中似乎存在一个错误,阻止它“识别”包含泛型声明的类。

以这个类声明为例:

@interface ABEBaseParseQueryViewController<CellType: UITableViewCell *, Object: id> : UIViewController <UITableViewDelegate, ABEDatasourceResponder>

如果我要在头文件中手动输入导出声明:

@property (weak, nonatomic) IBOutlet UITextField *titleField;

侧边栏中表示未连接 socket 的点不会出现。此外,当尝试在 IB 中将文件的所有者设置为此类时,我没有得到任何自动完成功能,这使得 xcode 似乎根本无法“识别”该类。即使我手动设置文件所有者,我也无法将 socket 连接到文件。

如果我从类中删除泛型声明,此问题将得到解决。 (侧边栏中的圆圈再次出现,我可以再次连接 socket )

还有其他人遇到过这个问题吗?现在我可以删除通用声明,连接 socket 并将其放回原处,但这似乎是一个糟糕的解决方法。

这是 xcode 7.2。



Best Answer-推荐答案


你完全正确。一旦你有了一个泛型(如本例所示):

ABEBaseParseQueryViewController<CellType: UITableViewCell *, Object: id>

该类不再是Interface BuilderCustom Class的选项。

您可以通过首先创建和选择来规避此限制:

ABEBaseParseQueryViewController

Pick ABEBaseParseQueryViewController before using generics

在 Interface Builder 中,稍后将您的 .h 更改为

ABEBaseParseQueryViewController<CellType: UITableViewCell *, Object: id>

请注意,此时您甚至无法在 Interface Builder 中选择通用的Custom Class

关于ios - 无法将 socket 连接到通用类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34364263/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4