swift - Identify Duplicates In Array -


i have array of custom objects , want know how identify objects duplicates. know how remove duplicates not functionality i'm after. im using swift 2.

example:

var movies: [movie] = ["batman v superman: dawn of justice", "batman v superman: dawn of justice", "deadpool"," "deadpool", "hardcore henry", "jason bourne", "jurassic world"] 

so want show table view list of movies above "batman" , "deadpool" highlighted.

for more clarity on i'm trying achieve @ screenshot. have list of movies 2 users select in previous view controller. want display selected movies in table view. want show if there movies both people selected.

enter image description here

based on comment have made simple example string arrays, can converted movie type:

let movies = ["batman","batman","flash","avengers"] var moviecounts:[string:int] = [:]     movie in movies {  moviecounts[movie] = (moviecounts[movie] ?? 0) + 1 } 

and can test so:

for (key, value) in moviecounts {  print("\(key) has been selected \(value) time/s") } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -