对于我的 iOS 应用程序,我有一个类似的模型
class Person {
var Id: Int
var Name: String
init(id: Int, name: String?) {
self.Id = id
self.Name = name ?? ""
}
}
然后稍后在我ViewController
从服务器加载数据时,我将一些人添加到数组中
class ViewController: UIViewController {
var people:[Person] = []
override func viewDidLoad() {
self.loadPeople()
}
func loadPeople() {
// This data will be coming from a server request
// so is just sample. It could have users which
// already exist in the people array
self.people.append(Person(id: "1", name: "Josh"))
self.people.append(Person(id: "2", name: "Ben"))
self.people.append(Person(id: "3", name: "Adam"))
}
}
我现在要做的是将people
数组变成 aSet<Person>
这样它就不会添加重复项。这是可能的还是我需要改变我的逻辑?