@@ -24,7 +24,7 @@ public protocol PingDelegate {
24
24
}
25
25
26
26
/// Describes all possible errors thrown within `SwiftyPing`
27
- public enum PingError : Error , Equatable {
27
+ public enum PingError : Error , Equatable , Hashable {
28
28
// Response errors
29
29
30
30
/// The response took longer to arrive than `configuration.timeoutInterval`.
@@ -712,14 +712,7 @@ public class SwiftyPing: NSObject {
712
712
713
713
// MARK: ICMP
714
714
715
- public struct IPv4Address : Equatable {
716
- public static func == ( lhs: IPv4Address , rhs: IPv4Address ) -> Bool {
717
- return lhs. bytes. 0 == rhs. bytes. 0 &&
718
- lhs. bytes. 1 == rhs. bytes. 1 &&
719
- lhs. bytes. 2 == rhs. bytes. 2 &&
720
- lhs. bytes. 3 == rhs. bytes. 3
721
- }
722
-
715
+ public struct IPv4Address : Equatable , Hashable {
723
716
public var bytes : ( UInt8 , UInt8 , UInt8 , UInt8 )
724
717
725
718
init ( a: UInt8 , b: UInt8 , c: UInt8 , d: UInt8 ) {
@@ -728,10 +721,24 @@ public struct IPv4Address: Equatable {
728
721
self . bytes. 2 = c
729
722
self . bytes. 3 = d
730
723
}
724
+
725
+ public static func == ( lhs: IPv4Address , rhs: IPv4Address ) -> Bool {
726
+ return lhs. bytes. 0 == rhs. bytes. 0 &&
727
+ lhs. bytes. 1 == rhs. bytes. 1 &&
728
+ lhs. bytes. 2 == rhs. bytes. 2 &&
729
+ lhs. bytes. 3 == rhs. bytes. 3
730
+ }
731
+
732
+ public func hash( into hasher: inout Hasher ) {
733
+ hasher. combine ( bytes. 0 )
734
+ hasher. combine ( bytes. 1 )
735
+ hasher. combine ( bytes. 2 )
736
+ hasher. combine ( bytes. 3 )
737
+ }
731
738
}
732
739
733
740
/// Format of IPv4 header
734
- public struct IPHeader : Equatable {
741
+ public struct IPHeader : Equatable , Hashable {
735
742
public var versionAndHeaderLength : UInt8
736
743
public var differentiatedServices : UInt8
737
744
public var totalLength : UInt16
@@ -770,7 +777,7 @@ public enum ICMPType: UInt8 {
770
777
// MARK: - Helpers
771
778
772
779
/// A struct encapsulating a ping response.
773
- public struct PingResponse : Equatable {
780
+ public struct PingResponse : Equatable , Hashable {
774
781
/// The randomly generated identifier used in the ping header.
775
782
public let identifier : UInt16
776
783
/// The IP address of the host.
0 commit comments