我有一个 searchController,当我尝试删除 searchController 中的文本时,它会崩溃消息。
提供的标识符不是唯一的
我尝试使用像这样的哈希函数来修复它,并使我的模型可散列和相等。但仍然无法解决问题,请帮助。这是我的代码,如果我的代码中有不清楚的地方。随时提及我,我会更新它:)
struct PhotosResults: Decodable {
var total, totalPages: Int
var results: [PhotoItem]
}
// MARK: - Result
struct PhotoItem: Decodable {
var id: String
var createdAt: String
var width, height: Int
var color: String
var likes: Int
var likedByUser: Bool
var description: String?
var user: User
var urls: Urls
}
extension PhotoItem: Hashable, Equatable {
static func == (lhs: PhotoItem, rhs: PhotoItem) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
// MARK: - Urls
struct Urls: Decodable {
var raw, full, regular, small: String
var thumb: String
}
// MARK: - User
struct User: Decodable {
var id, username, name, firstName: String
var lastName, instagramUsername, twitterUsername: String?
var portfolioUrl: String?
var profileImage: ProfileImage
}
extension User: Hashable, Equatable {
static func == (lhs: User, rhs: User) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
// MARK: - ProfileImage
struct ProfileImage: Decodable {
var small, medium, large: String
}