Swift has trouble parsing anonymous closure in the context of an if
logical expression. You can work around this issue by parenthesizing the count
expression:
if (myStructArray.filter{$0.isLocked == true}.count) < 4 {
// ^ ^
print("Fewer than 4 locked")
}
or
if (myStructArray.filter{$0.isLocked == true}.count < 4) {
// ^ ^
print("Fewer than 4 locked")
}
or
if myStructArray.filter({$0.isLocked == true}).count < 4 {
// ^ ^
print("Fewer than 4 locked")
}