-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from mdiep/add-identifiable-type
Implement `Identifiable` type in model with ids
- Loading branch information
Showing
15 changed files
with
108 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Identifiable.swift | ||
// Tentacle-OSX | ||
// | ||
// Created by Romain Pouclet on 2017-06-18. | ||
// Copyright © 2017 Matt Diephouse. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Identifiable { | ||
var id: ID<Self> { get } | ||
} | ||
|
||
public struct ID<Of: Identifiable> { | ||
let rawValue: Int | ||
} | ||
|
||
extension ID: ExpressibleByIntegerLiteral { | ||
public init(integerLiteral value: Int) { | ||
self.rawValue = value | ||
} | ||
} | ||
|
||
extension ID: Hashable { | ||
|
||
public var hashValue: Int { | ||
return rawValue.hashValue | ||
} | ||
|
||
} | ||
|
||
extension ID: Equatable { | ||
|
||
static public func == (lhs: ID, rhs: ID) -> Bool { | ||
return lhs.rawValue == rhs.rawValue | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.