Skip to content

Commit

Permalink
added filter, map, to SugarRecordResults
Browse files Browse the repository at this point in the history
  • Loading branch information
avielg committed Apr 6, 2015
1 parent c9157a9 commit 43d4694
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions library/Core/SugarRecordResults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,22 @@ public class SRResultsGenerator: GeneratorType {
return self.results[nextIndex--]
}
}

//MARK: Convenience Methods Extension

extension SugarRecordResults {
func filter<T>(predicate:(T) -> Bool) -> [T] {
var result = [T]()
for obj in self {
if predicate(obj as T) { result.append(obj as T) }
}
return result
}
func map<T, U>(transform:(T) -> (U)) -> [U] {
var result = [U]()
for obj in self {
result.append(transform(obj as T))
}
return result
}
}

0 comments on commit 43d4694

Please sign in to comment.