如何在 "does not conform to protocol" 出现时修复
How to fix "does not conform to protocol" when in it does
我正在尝试实施 git 项目 XLPagerTabStrip。
根据项目,每个控制器必须:
Every view controller provided by PagerTabStripDataSource's viewControllers(for:) method must conform to InfoProvider
但是下面的代码抛出:does not conform to protocol
extension UserProfileSubController: IndicatorInfoProvider {
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: "UserProfileSubController")
}
}
如果我想自动修复问题,它会重新实现相同的协议功能,然后抛出无效的重新声明。
如果您的控制器确实符合 does not conform to protocol
问题,您将如何解决?我错过了什么?非常感谢帮助。
PS: 我已经清理了项目、构建文件夹、删除了派生数据、重新启动并执行了 pod 更新以及 pod 的重新安装。
我不确定这是否有效,但试试这些:
- 将代码放在 class 而不是扩展中。
- 使用这个特定的 pod
pod 'XLPagerTabStrip', '~> 7.0'
检查 IndicatorInfo class 类似于以下方式:
public struct IndicatorInfo {
public var title: String?
public var image: UIImage?
public var highlightedImage: UIImage?
public init(title: String?) {
self.title = title
}
public init(image: UIImage?, highlightedImage: UIImage? = nil) {
self.image = image
self.highlightedImage = highlightedImage
}
public init(title: String?, image: UIImage?, highlightedImage: UIImage? = nil) {
self.title = title
self.image = image
self.highlightedImage = highlightedImage
}
}
而不是 public struct IndicatorInfo{} 您使用了 public protocol IndicatorInfo{}
而且我希望你一次只能使用一种协议class。
extension YourViewController : IndicatorInfoProvider {
// MARK: - Top Tab Bar Method - IndicatorInfoProvider
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: "titleStringHere", image: UIImage(named: "Your_Image_Name"))
/*or return IndicatorInfo(title: "titleStringHere") */
}
}
最后是copy/pasting/dependency问题。
重新开始并删除 pod 和依赖代码并重新安装最终解决了问题。
我正在尝试实施 git 项目 XLPagerTabStrip。
根据项目,每个控制器必须:
Every view controller provided by PagerTabStripDataSource's viewControllers(for:) method must conform to InfoProvider
但是下面的代码抛出:does not conform to protocol
extension UserProfileSubController: IndicatorInfoProvider {
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: "UserProfileSubController")
}
}
如果我想自动修复问题,它会重新实现相同的协议功能,然后抛出无效的重新声明。
如果您的控制器确实符合 does not conform to protocol
问题,您将如何解决?我错过了什么?非常感谢帮助。
PS: 我已经清理了项目、构建文件夹、删除了派生数据、重新启动并执行了 pod 更新以及 pod 的重新安装。
我不确定这是否有效,但试试这些:
- 将代码放在 class 而不是扩展中。
- 使用这个特定的 pod
pod 'XLPagerTabStrip', '~> 7.0'
检查 IndicatorInfo class 类似于以下方式:
public struct IndicatorInfo {
public var title: String?
public var image: UIImage?
public var highlightedImage: UIImage?
public init(title: String?) {
self.title = title
}
public init(image: UIImage?, highlightedImage: UIImage? = nil) {
self.image = image
self.highlightedImage = highlightedImage
}
public init(title: String?, image: UIImage?, highlightedImage: UIImage? = nil) {
self.title = title
self.image = image
self.highlightedImage = highlightedImage
}
}
而不是 public struct IndicatorInfo{} 您使用了 public protocol IndicatorInfo{}
而且我希望你一次只能使用一种协议class。
extension YourViewController : IndicatorInfoProvider {
// MARK: - Top Tab Bar Method - IndicatorInfoProvider
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: "titleStringHere", image: UIImage(named: "Your_Image_Name"))
/*or return IndicatorInfo(title: "titleStringHere") */
}
}
最后是copy/pasting/dependency问题。 重新开始并删除 pod 和依赖代码并重新安装最终解决了问题。