Skip to content

Commit

Permalink
Better handle equality checks of model types
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
bilaalrashid committed Jun 2, 2024
1 parent b66725a commit 1cdd7a9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/BbcNews/Models/Discovery/FDTopicButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ public struct FDTopicButton: Codable, Equatable, Hashable {
self.resourceId = resourceId
self.trackedEvents = trackedEvents
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.resourceId)
}

// swiftlint:disable:next operator_whitespace
public static func ==(lhs: FDTopicButton, rhs: FDTopicButton) -> Bool {
return lhs.resourceId == rhs.resourceId
}
}
9 changes: 9 additions & 0 deletions Sources/BbcNews/Models/Discovery/FDTrackedEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ public struct FDTrackedEvent: Codable, Equatable, Hashable {
self.event = event
self.trackers = trackers
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.event)
}

// swiftlint:disable:next operator_whitespace
public static func ==(lhs: FDTrackedEvent, rhs: FDTrackedEvent) -> Bool {
return lhs.event == rhs.event
}
}
9 changes: 9 additions & 0 deletions Sources/BbcNews/Models/Discovery/Link/FDLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ public struct FDLink: Codable, Equatable, Hashable {
self.destinations = destinations
self.trackers = trackers
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.destinations)
}

// swiftlint:disable:next operator_whitespace
public static func ==(lhs: FDLink, rhs: FDLink) -> Bool {
return lhs.destinations == rhs.destinations
}
}
9 changes: 9 additions & 0 deletions Sources/BbcNews/Models/Discovery/Link/FDLinkDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ public struct FDLinkDestination: Codable, Equatable, Hashable {
return nil
}
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.id)
}

// swiftlint:disable:next operator_whitespace
public static func ==(lhs: FDLinkDestination, rhs: FDLinkDestination) -> Bool {
return lhs.id == rhs.id
}
}
10 changes: 10 additions & 0 deletions Sources/BbcNews/Models/Result/FDData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public struct FDData: Codable, Equatable, Hashable {
self.items = items
self.trackers = trackers
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.metadata)
hasher.combine(self.items)
}

// swiftlint:disable:next operator_whitespace
public static func ==(lhs: FDData, rhs: FDData) -> Bool {
return lhs.metadata == rhs.metadata && lhs.items == rhs.items
}
}
9 changes: 9 additions & 0 deletions Sources/BbcNews/Models/Story/FDVideoPortraitStory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ public struct FDVideoPortraitStory: Codable, Equatable, Hashable {
self.subtext = subtext
self.media = media
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.id)
}

// swiftlint:disable:next operator_whitespace
public static func ==(lhs: FDVideoPortraitStory, rhs: FDVideoPortraitStory) -> Bool {
return lhs.id == rhs.id
}
}
9 changes: 9 additions & 0 deletions Sources/BbcNews/Models/Story/Media/FDMediaSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ public struct FDMediaSource: Codable, Equatable, Hashable {
self.canAutoPlay = canAutoPlay
self.episodePid = episodePid
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.id)
}

// swiftlint:disable:next operator_whitespace
public static func ==(lhs: FDMediaSource, rhs: FDMediaSource) -> Bool {
return lhs.id == rhs.id
}
}

0 comments on commit 1cdd7a9

Please sign in to comment.