If you really want to use identity operator (===) for your checkItem, you can declare your Item as a class protocol:
protocol Item: class {
var name: String! {get set}
var value: Int! {get set}
}
class UserList {
var items: [Item]!
func checkItem(item: Item) -> Bool{
return items.contains {$0 === item}
}
}
(I do not understand why you need implicitly unwrapped Optionals, so I have kept them there. But I myself would never use so many IUOs.)
But I wonder if identity is what you want:
class ClassItem: Item {
var name: String!
var value: Int!
init(_ name: String, _ value: Int) {
self.name = name
self.value = value
}
}
let myList = UserList()
myList.items = [ClassItem("aaa", 1), ClassItem("bbb", 2)]
var result = myList.checkItem(item: ClassItem("aaa", 1))
print(result) //->false
If the result false is not what you expect, you need to define your own equality for the Item and define your checkItem(item:) with it.