I'm primarily an iOS dev, but have been doing some UI Unit Testing in Visual Studio in C#. I came across this in C#
var table = Driver.FindElements(By.TagName("table"));
return table.First(t => t.Displayed == true);
Objective-C is not known for it's pretty or terse syntax. The two options I've come up with are:
NSArray *a = @[ @1, @2, @3, @4 ];
NSLog(@">= 3: %@", [a filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF >= 3"]]);
NSLog(@">= 3: %@", [a filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id obj, id bindings) { return [obj integerValue] >= 3; }]]);
To take only the first object from either filtered array, just append .firstObject
.
In Swift, it gets better, with nicer block syntax, better type inference and auto-closures.