func ==(lhs: ViewController.ItemType,rhs: ViewController.ItemTypE) -> Bool { // For some reasons for different types e.g. .CType and .AType it returns true switch(lhs,rhs) { case (.AType,.ATypE): return true case (let .bType(type1),let .bType(type2)): return type1 == type2 case (.CType,.CTypE): return true case (.DType,.DTypE): return true case (.EType,.ETypE): return true default: return false } } class ViewController: UIViewController { enum ItemType { case AType case BType(int) case CType case DType case EType } override func viewDidLoad() { super.viewDidLoad() let array:[ItemType] = [.AType,.bType(10),.CType,.DType,.EType] let array2 = array.filter { (itemType:ItemTypE) -> Bool in return itemType == .CType } // Prints 1 on [-ONone] optimization and 4 for [-OFast] optimization. print("Items \(array2.count):\n\(array2)") } }
struct Foo { enum Enum { case A case B case C(int) } } func ==(lhs: Foo.Enum,rhs: Foo.Enum) -> Bool { print("comparing \(lhs) == \(rhs) -> ",terminator: "") switch(lhs,rhs) { case (.A,.A): return true case (.b,.b): return true default: return false } } func test() { print( Foo.Enum.A == .b) print([ Foo.Enum.A ][0] == .b) print([ Foo.Enum.A ].first! == .b) for itemType in [ Foo.Enum.A ] { print(itemType == .b) } } test()
在-Onone构建此打印预期的四倍真.在优化的构建中,它打印…
comparing A == B -> false comparing A == B -> false comparing A == B -> true comparing A == B -> true
该错误在以下情况下消失:
>测试在外部文件范围内执行(不在函数中)
>使用普通函数代替operator ==
>枚举不是嵌套在另一种类型中
>删除案例C或关联类型
>打印语句插入到开关案例中
我一直在测试Xcode 7.1.这个bug肯定应该在bugreport.apple.com上提交
以上是大佬教程为你收集整理的ios – 优化级别会影响比较枚举全部内容,希望文章能够帮你解决ios – 优化级别会影响比较枚举所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。