Conditions combined with logic OR - Swift (error) -


i`m following tutorial ray wenderlich
(http://www.raywenderlich.com/81952/intro-object-oriented-design-swift-part-1)

this function gives error. problem line logic or operator ( || ). can`t find cause of issue.

the function:

func turn (degrees: int) -> string {     var normaldegrees = degrees     let degreesinacircle = 360      if (normaldegrees > degreesinacircle || normaldegrees < -degreesinacircle) {         normaldegrees = normaldegrees % degreesinacircle     }      return "turn \(normaldegrees) degrees" } 

the error get, says: expected "," separator

the function part of class, don´t see why should problem. i´ll upload code if necessary. i´m working code in playground file.

the rest of class:

class vehicle {     var brandname = ""     var modelname = ""     let modelyear = 0     var powersource = ""     var numberofwheels = 0      func goforward() -> string {         return ""     }      func gobackwards() -> string {         return ""     }      func stopmoving() -> string {         return ""     }      func turn (degrees: int) -> string {         var normaldegrees = degrees         let degreesinacircle = 360          if normaldegrees > degreesinacircle || normaldegrees < -degreesinacircle {             normaldegrees = normaldegrees % degreesinacircle         }           return "turn \(normaldegrees) degrees"     }      func changegears (newgearname: string) -> string {         return "put \(modelname) \(newgearname) gear"     }      func makenoise () -> string {         return ""     } } 

the condition in if statement weird: when should execute when either first value greater second or second greater first, that's checking whether values indifferent! so

if normaldegrees > degreesinacircle || normaldegrees < degreesinacircle 

is equal

if normaldegrees != degreesinacircle 

also can convert

func turn (degrees: int) -> string {     var normaldegrees = degrees 

to

func turn (var normaldegrees: int) -> string { 

(is same, more concise)

there more weird things in code. think want simple:

func turn(degrees: int) -> string {     return "turn \(degrees % 360) degrees" } 

(try out)


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -