2014-10-13 1 views
-1

저는 프로그래밍 할 때 새로운 종류입니다. 가이드 단계를 따라 가면서 모든 것이 잘 작동했지만,이 시점에서 나는 막혔습니다. 나는 모든 것을 확인했지만, 그것은 Expected expressions in list of expressions, Expected ',' separator'()' is not convertible to 'Orientation'스위프트 : 예상 ','실패?

import Foundation 
import SpriteKit 

let NumOrientations: UInt32 = 4 

enum Orientation: Int, Printable { 
    case Zero = 0, Ninety, OneEighty, TwoSeventy 

    var description: String { 
     switch self { 
     case .Zero: 
      return "0" 
     case .Ninety: 
      return "90" 
     case .OneEighty: 
      return "180" 
     case .TwoSeventy: 
      return "270" 
     } 
    } 

    static func random() -> Orientation { 
     return Orientation.fromRaw(<#Int#>(arc4random_uniform(NumOrientations))) 
    } 

// #1 
    static func rotate(orientation:Orientation, clockwise: Bool) -> Orientation { 
     var rotated = orientation.toRaw() + (clockwise ? 1 : -1) 
     if rotated > Orientation.TwoSeventy.toRaw() { 
      rotated = Orientation.Zero.toRaw() 
     } else if rotated < 0 { 
      rotated = Orientation.TwoSeventy.toRaw() 
     } 
     return Orientation.fromRaw(rotated)! 
    } 
} 

어떤 도움으로, 실패를 같은 내가 그것을 해결하고 실패와 함께 올 것이다 구축을 시도 할 때마다이라고 말했다?

+0

내가 스위프트 모르는

당신의 rotate 기능 마찬가지로

static func rotate(orientation:Orientation, clockwise: Bool) -> Orientation! { var rotated = orientation.toRaw() + (clockwise ? 1 : -1) if rotated > Orientation.TwoSeventy.toRaw() { rotated = Orientation.Zero.toRaw() } else if rotated < 0 { rotated = Orientation.TwoSeventy.toRaw() } return Orientation.fromRaw(rotated) } 

주 그러나이 선은 분명히 문제입니다 :'Orientation.fromRaw (<#Int#> (arc4random_uniform (NumOrientations)))'를 반환하십시오. – rmaddy

+2

오류가 발생한 줄을 말하면 도움이 될 것입니다. –

+0

<#Int#>은 IDE에서 자동 완성을 돕는 텍스트 Xcode 삽입물입니다. 일반적으로 탭을 클릭하면 해당 텍스트 블록을 선택하고 (Int라고 말하면) 사용자가 입력합니다. 확실히 제거해야합니다. – rickerbh

답변

1

당신의 < # Int 인 #> 구문을 가지고 어디 확실하지 않다, 그러나 이것은 나를 위해 작동 : 그것이 아니므로 반환 형식이 Orientation!하지 Orientation해야

static func random() -> Orientation! { 
    return Orientation.fromRaw(Int(arc4random_uniform(NumOrientations))) 
} 

하는 것으로 선택 과목. 당신이 회전 기능 인스턴스 메서드 할 수있다 오히려, 이는 정적보다 더 객체 지향 설계

func rotate(#clockwise:Bool) -> Orientation! { 
    var rotated = self.toRaw() + (clockwise ? 1 : -1) 
    if rotated > Orientation.TwoSeventy.toRaw() { 
     rotated = Orientation.Zero.toRaw() 
    } else if rotated < 0 { 
     rotated = Orientation.TwoSeventy.toRaw() 
    } 
    return Orientation.fromRaw(rotated) 
}