首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swift 4.0中的@IBInspectable

Swift 4.0中的@IBInspectable
EN

Stack Overflow用户
提问于 2017-10-06 07:39:50
回答 1查看 2.7K关注 0票数 1

在迁移到Swift 4.0时,我面临着@IBInspectable的一个问题,

代码语言:javascript
复制
open class SVContactBubbleView: UIView 
{
   @IBInspectable open var dataSource: SVContactBubbleDataSource? //ERROR..!!
   @IBInspectable open var delegate: SVContactBubbleDelegate? //ERROR..!!
}

public protocol SVContactBubbleDataSource
{
    //Methods here
}

public protocol SVContactBubbleDelegate
{
    //Methods here
}

出现的错误是:

属性不能标记为@IBInspectable,因为它的类型不能在目标-C中表示。

Swift 3,它运行得很好。我不明白Swift 4到底出了什么问题。

此外,编译器没有显示任何建议。它只是显示了一个错误消息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-10 10:08:30

在Swift 4中为委托和数据源添加符号@objc (如下面的代码所示)

代码语言:javascript
复制
open class SVContactBubbleView: UIView {
    @IBInspectable open var dataSource: SVContactBubbleDataSource? 
    @IBInspectable open var delegate: SVContactBubbleDelegate? 
}

@objc  // add notation here
public protocol SVContactBubbleDataSource
{
    //Methods here
}


@objc  // add notation here
public protocol SVContactBubbleDelegate
{
    //Methods here
}

这是裁判。具有错误解析的快照:

以下是苹果用于@objc符号的文档-- 议定书-任择议定书要求

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46600685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档