[英]Type [Node] does not conform 'Equatable' in Swift 4.0?
I use Eureka in my Project,and I want use type [Node] for Cell's Value type: 我在我的项目中使用Eureka,并且要为Cell的Value类型使用[Node]类型:
final class TreeTVCell: Cell<[Node]>,CellType{//#1:compiling Error in Swift 4.0
}
As you know , Cell's Value type must conform protocol Equatable,and class Node wrote by Objc,it's very simple: 如您所知,Cell的Value类型必须符合协议Equatable,并且由Objc编写的Node类非常简单:
#import "Node.h"
@implementation Node
- (instancetype)initWithParentId : (int)parentId nodeId : (int)nodeId name : (NSString *)name depth : (int)depth expand : (BOOL)expand{
self = [self init];
if (self) {
self.parentId = parentId;
self.nodeId = nodeId;
self.name = name;
self.depth = depth;
self.expand = expand;
}
return self;
}
@end
My project compiled OK in Swift 4.1 (Xcode 9.3.1),But if I open project with Xcode 9.2 (Swift 4.0),it will be comiled failed, it's complain that : 我的项目在Swift 4.1(Xcode 9.3.1)中编译正常,但是如果我使用Xcode 9.2(Swift 4.0)打开项目,它将被编译失败,它抱怨:
Type '[Node]' does not conform to protocol 'Equatable'
类型“ [Node]”不符合协议“ Equatable”
my Q is why it's compiled ok in Swift 4.1 and failed in Swift 4.0? 我的问题是为什么它在Swift 4.1中可以正常编译,而在Swift 4.0中却失败? and How to fix it in Swift 4.0?
以及如何在Swift 4.0中修复它? Thanks :)
谢谢 :)
Prior to Swift 4.1, Arrays of Equatable are not themselves Equatable. 在Swift 4.1之前,可等于数组本身不是可等于数组。 This isn't something you can fix in 4.0 directly;
您无法直接在4.0中修复此问题; it lacks conditional conformances.
它缺乏条件一致性。 You would have to wrap the Array in some other type (we usually call it "boxing" the type) and make that Equatable.
您将不得不将Array包装为其他某种类型(我们通常将其包装为“装箱”类型),并使该数组等于Equatable。 Upgrade to Swift 4.1.
升级到Swift 4.1。
See Conditional Conformance in the Standard Library for more details. 有关更多详细信息,请参见标准库中的条件一致性 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.