2

I have an if let statement with a where clause in Swift2 but the syntax is not correct for Swift3.

if let car = createCar(), let color = car.color where color == UIColor.redColor() { }

How do you convert this code to Swift3?

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
Inna Black
  • 251
  • 3
  • 9
  • What are you asking? How is what in Swift 3? You have two lines of unrelated code in your question and nothing else. What is your question? – Fogmeister Sep 19 '16 at 14:31
  • 2
    @Fogmeister The `where` clause – which is not available in Swift 3 – is the relation. – vadian Sep 19 '16 at 14:33
  • @vadian ah ok. Well there's no reason to not put that in the question. A question should not require the reader to interpret what is being asked. – Fogmeister Sep 19 '16 at 14:34
  • @Fogmeister Actually it's in the question: *if let **where** statements ... convert ... to swift3* ;-) – vadian Sep 19 '16 at 14:37
  • @vadian see edit. How it makes everything much clearer :) It makes it so much easier when you take 30 seconds to write an actual question rather than "Need converting to Swift 3". I realise it's not your question :) But the OP has gone quiet :) – Fogmeister Sep 19 '16 at 14:37
  • Thank you for your help) I agree that short questions aren't understood. – Inna Black Sep 19 '16 at 14:45
  • Possible duplicate of [Usage of where in if let assignment in Swift](http://stackoverflow.com/questions/38762513/usage-of-where-in-if-let-assignment-in-swift) – Grimxn Feb 06 '17 at 11:04

1 Answers1

14

The problem is actually in the statement, neither swift2 nor swift3 will accept it, the right for swift3 is:

if let car = createCar(), car.color == UIColor.red { }
Jans
  • 11,064
  • 3
  • 37
  • 45