4 ms·
Yeah, I found that line hideous - ridiculously unintuitive and hard to read compared to the equivalent in say, ruby. Maybe the whole essay would have been bett
by glenra 15y ago
Yeah, I found that line hideous - ridiculously unintuitive and hard to read compared to the equivalent in say, ruby.
Maybe the whole essay would have been better framed something like: "Objective C: not quite as bad as Java!"
- jasonlotito 15y agoJust curious, for comparison: what would the equivalent be in Ruby?
- akmiller 15y agomy_array.select { |item| item == somefiltervalue } At least that's one way to do it in ruby.
- rbxbx 15y agofilteredArray = [allRecords filteredArrayUsingPredicate: [NSPredicate predicateWithFormat:@"someField == %d", someFieldFilterValue]]; in ruby: all_records.select {|r| r.some_field == some_field_filter_value} in clojure: (filter #(= % some-filter-value) all-records) in haskell: filter (\someField -> x == someFilterValue) allRecords
- icodestuff 15y agoLet's be fair, in Objective-C, this could be actually more like NSIndexSet *indicies = [allRecords indexesOfObjectsPassingTest:^ (id obj, NSUInteger idx, BOOL *stop) { return [obj someField] == someFieldFilterValue; }]; filteredArray = [allRecords objectsAtIndexes:indicies]; rather than what the article had in mind. EDIT: oh, someFieldFilterValue was an integer, wasn't it. Fixed.