diff options
Diffstat (limited to 'SystemCollectionsGeneric/SystemCollectionsGeneric/Enumerator.swift')
-rw-r--r-- | SystemCollectionsGeneric/SystemCollectionsGeneric/Enumerator.swift | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/SystemCollectionsGeneric/SystemCollectionsGeneric/Enumerator.swift b/SystemCollectionsGeneric/SystemCollectionsGeneric/Enumerator.swift new file mode 100644 index 0000000..b5f8c91 --- /dev/null +++ b/SystemCollectionsGeneric/SystemCollectionsGeneric/Enumerator.swift @@ -0,0 +1,53 @@ +// +// Enumerator.swift +// DNSwift +// +// Created by Matthew S on 7/28/14. +// Copyright (c) 2014 Matthew S. All rights reserved. +// + +import Foundation + +public class Enumerator<T> : IEnumerator { + public var Current: T { + get { + return Objects[CurrentIndex]; + } + } + + public var CurrentIndex = 0; + public var Objects: [T]; + + public init(objs: [T]) { + self.Objects = objs; + } + + public func MoveNext() -> Bool { + self.CurrentIndex = CurrentIndex + 1; + if(CurrentIndex >= Objects.count) { + CurrentIndex = (Objects.count - 1); + return false; + } + return true; + } + + public func Reset() { + CurrentIndex = 0; + } + + //Generator compliance + public func next() -> T? + { + if(self.MoveNext()) { + return self.Objects[self.CurrentIndex]; + //return Current; + } + else { + return nil; + } + } + + public func Dispose() { + + } +}
\ No newline at end of file |