Rutger Huijsmans Rutger Huijsmans - 16 days ago 4x
Swift Question

Checking values within tuple that contains only booleans

I've constructed a tuple:

var groupUsersFlags = (false, false, false, false)

Throughout the screen these values get flipped over to true. So:

groupUsersFlags.0 = true
groupUsersFlags.1 = true

Is there any way to check if all the values are true at some point?


I would agree with the idea of using another data type in this case. However, to answer the question, you can check if all the values are true like this:

groupUsersFlags.0 && groupUsersFlags.1 && groupUsersFlags.2 && groupUsersFlags.3

Or, using reflection (use as your own risk):

Mirror(reflecting: groupUsersFlags).children.reduce(true) { $0 && $1.value as! Bool }