i'm having difficulty for defining my question in title so if my title is not appropriate then please do correct me ok so thing is that i have an
NSArray
named results
which is fetched from CoreData
and in this array the items have date
key which is of NSDate type . i want to predicate the NSArray
according to the months on Date
key , and am able to do that manually this is how am doing this :
let predicated = NSPredicate(format: "date >= %@ AND date <= %@", start, End)
var filtered = results.filteredArrayUsingPredicate(predicated)
here start
and end
are NSdate
which are first and last date of a given month say am predicating something like "give me the results which are between 1 jan to 31 jan" and its working fine
but i want to predicate my whole result
array in a way so that i don't have to provide the date range , like a function which will take the NSArray
and give me the output with variables of months like
func filterResultArray(NSArray) -> name of months with results {
// here predicate the whole array and add them to the founded months variable
}
print( "\(filterResultArray(resultsArray) )") // should print :
jan = 5 , feb = 18 , march = 5 , may = 87
please tell me what am trying to do using this type of approach is even possible or not and if yes the please give me a little hint or direction about how am gonna do that it'll be so helpful for me
for better understanding please see the example:
example - myArray = [ "1,01,2016", "4,01,2016" ,"28,01,2016", "6,02,2016" "25,02,2016", "29,02,2016" "4,03,2016", "4,04,2016" "10,04,2016", "24,04,2016" "9,05,2016", "29,05,2016" "17,05,2016", "24,05,2016" "12,06,2016", "13,06,2016" ]
now how can i filter this array so that i can get a results something like :
January = 3
feb = 3
march = 1
april = 3
may = 4
june = 2