gpt4 book ai didi

swift - 如何使 struct 和 typealias 符合@objc

转载 作者:搜寻专家 更新时间:2023-10-30 23:15:07 25 4
gpt4 key购买 nike

是否有可能使 struct 和/或 typealias 符合 @objc?我希望创建可选的协议(protocol)函数,一个返回一个 struct,另一个返回一个 typealias

public typealias SwiperData = (image: UIImage, title: String)

public struct SwiperPeekViewControllers{
public var parentViewController: UIViewController!
public var contentViewController: UIViewController!
public init(parentVC: UIViewController, contentVC: UIViewController){
parentViewController = parentVC
contentViewController = contentVC
}
}

协议(protocol)

    @objc public protocol SwiperPeekViewDelegate: class{
func didUndoAction(index: Int, dataSource: SwiperData)
// Method cannot be a member of an @objc protocol because the type of the parameter 2 cannot be represented in Objective-C
func swiperPeekViewControllers()->SwiperPeekViewControllers
func swiperPeekViewSize()->CGSize
}

最佳答案

您不能将类型别名导出到 Objective-C。你不能为元组做这件事。但是,关于 typealias,仍然可以为某些结构编写 Obj-C typedef 并在 Swift 中使用它,它将导出为 typealias

关于swift - 如何使 struct 和 typealias 符合@objc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37667326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com