2016-10-16 5 views
5

부재 '>'에 대한 모호한 참조 : I '는스위프트 3 오류 : I는 스위프트 컴파일러이 오류의 감지를 할 수없는

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 

    ... 
} 

: 여기

error: ambiguous reference to member '>' 
     let moveDirection = dx > 0 ? .right : .left 

는 코드 dx0 ~ CGFloat을 전송하거나 0.0을 사용하는 등 여러 가지 시도를했지만 지금까지 아무 것도 작동하지 않았습니다.

누군가가 왜 이런 일이 일어나고 어떻게 해결할 수 있습니까?

전체 오류 메시지 :

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 
        ^

답변

7

오류 메시지가 잘못된 것입니다. 문제는 당신이 .left.right이 무엇인지에 대한 스위프트에게 더 많은 정보를 제공 할 필요가 있다는 것입니다 :

let moveDirection = dx > 0 ? MoveDirection.right : .left 

또는

let moveDirection: MoveDirection = dx > 0 ? .right : .left 
+1

감사합니다! 희망 그들은 오류 메시지를 수정합니다. – iosdude