0

Well i see this is valid swift code:

var R, G, B, opacity: Double

Since this code will run execute with no problems, Say i wanted to set all the above variables to 0.0, How would it be declared and initialized ? because let R, G, B, opacity: Double = 0.0 throws a Type annotation missing in pattern error

I know in Python

a = b = c = d = e = g = h = i = j = True

or Javascript

var a = b = c = d = e = g = h = i = j = true

2 Answers2

0

The assignment operator (=) doesn’t return a value, to prevent it from being mistakenly used when the equal to operator (==) is intended. – https://docs.swift.org/swift-book/LanguageGuide/BasicOperators.html

let (R, G, B, opacity) = (0.0, 0.0, 0.0, 0.0)

is the cleanest you can do, but you really should make a struct.

struct Color {
  var (r, g, b, opacity) = (0.0, 0.0, 0.0, 0.0)
}
-1

You can define multiple variable of same type like below:

var R, G, B, opacity: Double

Or

var R = 0.0, G = 0.0, B = 0.0, opacity= 0.0
Abdul Karim Khan
  • 4,256
  • 1
  • 26
  • 30