首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Swift 3:错误:对Swift‘>成员的模糊引用

Swift 3:错误:对Swift‘>成员的模糊引用
EN

Stack Overflow用户
提问于 2016-10-16 19:17:55
回答 1查看 4.1K关注 0票数 5

我无法理解Swift编译器中的错误:

代码语言:javascript
运行
复制
error: ambiguous reference to member '>'
        let moveDirection = dx > 0 ? .right : .left

以下是代码:

代码语言:javascript
运行
复制
enum MoveDirection {
    case none
    case left
    case right
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    guard let touch = touches.first else {
        return;
    }

    let location = touch.location(in: humanPlayerScreen)
    let previousLocation = touch.previousLocation(in: humanPlayerScreen)

    let dx = location.x - previousLocation.x
    let dy = location.y - previousLocation.y
    let moveDirection = dx > 0 ? .right : .left // error

    ...
}

我尝试过很多事情,比如将dx0都转换为CGFloat,或者使用0.0,但到目前为止,它们都没有起作用。

有人能解释一下为什么会发生这种情况吗?如何解决呢?

完全错误消息:

代码语言:javascript
运行
复制
Swift.>:5:13: note: found this candidate
public func >(lhs: UInt8, rhs: UInt8) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: Int8, rhs: Int8) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: UInt16, rhs: UInt16) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: Int16, rhs: Int16) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: UInt32, rhs: UInt32) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: Int32, rhs: Int32) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: UInt64, rhs: UInt64) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: Int64, rhs: Int64) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: UInt, rhs: UInt) -> Bool
            ^
Swift.>:5:13: note: found this candidate
public func >(lhs: Int, rhs: Int) -> Bool
            ^
Foundation.Date:95:24: note: found this candidate
    public static func >(lhs: Date, rhs: Date) -> Bool
                       ^
Foundation.IndexPath:51:24: note: found this candidate
    public static func >(lhs: IndexPath, rhs: IndexPath) -> Bool
                       ^
Foundation.IndexSet.Index:5:24: note: found this candidate
    public static func >(lhs: IndexSet.Index, rhs: IndexSet.Index) -> Bool
                       ^
CoreMedia.>:1:13: note: found this candidate
public func >(time1: CMTime, 

time2: CMTime) -> Bool
            ^
Swift.>:10:13: note: found this candidate
public func ><T : Comparable>(lhs: T, rhs: T) -> Bool
            ^
Swift.>:1:13: note: found this candidate
public func ><T : FloatingPoint>(lhs: T, rhs: T) -> Bool
            ^
Swift.>:1:13: note: found this candidate
public func ><T : _SwiftNewtypeWrapper where T.RawValue : Comparable>(lhs: T, rhs: T) -> Bool
            ^
Swift.>:12:13: note: found this candidate
public func ><A : Comparable, B : Comparable>(lhs: (A, B), rhs: (A, B)) -> Bool
        ^
Swift.>:12:13: note: found this candidate
public func ><A : Comparable, B : Comparable, C : Comparable>(lhs: (A, B, C), rhs: (A, B, C)) -> Bool
            ^
Swift.>:12:13: note: found this candidate
public func ><A : Comparable, B : Comparable, C : Comparable, D : Comparable>(lhs: (A, B, C, D), rhs: (A, B, C, D)) -> Bool
            ^
Swift.>:12:13: note: found this candidate
public func ><A : Comparable, B : Comparable, C : Comparable, D : Comparable, E : Comparable>(lhs: (A, B, C, D, E), rhs: (A, B, C, D, E)) -> Bool
            ^
Swift.>:12:13: note: found this candidate
public func ><A : Comparable, B : Comparable, C : Comparable, D : Comparable, E : Comparable, F : Comparable>(lhs: (A, B, C, D, E, F), rhs: (A, B, C, D, E, F)) -> Bool
            ^
Swift.Comparable:158:24: note: found this candidate
    public static func >(lhs: Self, rhs: Self) -> Bool
                       ^
Swift.LazyFilterIndex<Base>:7:24: note: found this candidate
    public static func >(lhs: LazyFilterIndex<Base>, rhs: LazyFilterIndex<Base>) -> Bool
                       ^
EN

Stack Overflow用户

回答已采纳

发布于 2016-10-16 19:24:06

错误信息具有误导性。问题是,您需要向Swift提供更多关于.left.right的信息:

代码语言:javascript
运行
复制
let moveDirection = dx > 0 ? MoveDirection.right : .left

代码语言:javascript
运行
复制
let moveDirection: MoveDirection = dx > 0 ? .right : .left
票数 8
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40074410

复制
相关文章

相似问题

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