I have two Array
holding the instances of class MYItems
. FavoriteItems
holds the favorite items from the array Items
var Items :[MYItems] = []
var favoriteItems = [MYItems]()
Now i want to check if the Items array contains the favoriteItems in the . How can i acheive this? i tried using the below Find method
if let index = find(favoriteItems, Items[indexPath.row]){
println("found item")
}else{
println("doesnotcontains item")
}
I tried using the below but that doesnot help too..
if contains(favoriteItems, Items[indexPath.row]){
println("found item")
}else{
println("doesnot contain item")
}
But it always goes to the else block? Why is this happening when i contain one of the items in array for sure.
I suspect you are searching for the problem in the wrong place. You code on how to search through the array is indeed correct.
Does work in swift 1.2. The fourth item of
favoriteItems
(5) is indeed insideItems
and it also does printfound item
For your use with custom classes, you should make your class
Equatable
to do so you much make the class conform to theEquatable
protocol.