Skip to content

Commit

Permalink
Merge pull request AliSoftware#156 from kandelvijaya/improvement/equa…
Browse files Browse the repository at this point in the history
…tableIntoItsExtension

Added Equatable conformance on the site of declaration
  • Loading branch information
ilyapuchka authored Apr 14, 2017
2 parents 22d1969 + d809177 commit 199b1ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
14 changes: 7 additions & 7 deletions Sources/Definition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//

///A key used to store definitons in a container.
public struct DefinitionKey : Hashable, CustomStringConvertible {
public struct DefinitionKey: Hashable, CustomStringConvertible {
public let type: Any.Type
public let typeOfArguments: Any.Type
public private(set) var tag: DependencyContainer.Tag?
Expand All @@ -47,15 +47,15 @@ public struct DefinitionKey : Hashable, CustomStringConvertible {
tagged.tag = tag
return tagged
}

}

/// Check two definition keys on equality by comparing their `type`, `factoryType` and `tag` properties.
public func ==(lhs: DefinitionKey, rhs: DefinitionKey) -> Bool {
return
lhs.type == rhs.type &&
/// Check two definition keys on equality by comparing their `type`, `factoryType` and `tag` properties.
public static func ==(lhs: DefinitionKey, rhs: DefinitionKey) -> Bool {
return
lhs.type == rhs.type &&
lhs.typeOfArguments == rhs.typeOfArguments &&
lhs.tag == rhs.tag
}

}

///Dummy protocol to store definitions for different types in collection
Expand Down
22 changes: 13 additions & 9 deletions Sources/Dip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class DependencyContainer {

- seealso: `DependencyTagConvertible`
*/
public enum Tag: Equatable {
public enum Tag {
case String(StringLiteralType)
case Int(IntegerLiteralType)
}
Expand Down Expand Up @@ -477,13 +477,17 @@ extension DependencyContainer.Tag: ExpressibleByIntegerLiteral {

}

public func ==(lhs: DependencyContainer.Tag, rhs: DependencyContainer.Tag) -> Bool {
switch (lhs, rhs) {
case let (.String(lhsString), .String(rhsString)):
return lhsString == rhsString
case let (.Int(lhsInt), .Int(rhsInt)):
return lhsInt == rhsInt
default:
return false
extension DependencyContainer.Tag: Equatable {

public static func ==(lhs: DependencyContainer.Tag, rhs: DependencyContainer.Tag) -> Bool {
switch (lhs, rhs) {
case let (.String(lhsString), .String(rhsString)):
return lhsString == rhsString
case let (.Int(lhsInt), .Int(rhsInt)):
return lhsInt == rhsInt
default:
return false
}
}

}

0 comments on commit 199b1ae

Please sign in to comment.