Rutger Huijsmans Rutger Huijsmans - 1 year ago 56
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?

Answer Source

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 }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download