-
-
Save fitomad/3f1a3ec9112fbd5f36bd275e360e4bb4 to your computer and use it in GitHub Desktop.
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
public class Pool<Element> | |
{ | |
/// Los elementos que gestionamos | |
public private(set) var elements: [Element] | |
/// Para saber los que hay disponibles | |
public var elementsAvailables: Int | |
{ | |
return self.elements.count | |
} | |
/** | |
Nuevo pool con sus elementos | |
*/ | |
public init(elements: [Element]) | |
{ | |
self.elements = elements | |
} | |
/** | |
Recuperamos un elemento | |
*/ | |
public func getElement() -> Element? | |
{ | |
self.elements.removeFirst() | |
} | |
/** | |
Reponemos el elemento | |
*/ | |
public func restore(_ element: Element) -> Void | |
{ | |
self.elements.append(element) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment