The successor() method returns the next value after the current one (if there is one, if the current value is 0, then the successor() call will return 1, etc.)
A typical successor () implementation would look like this:
class ForWardIndexDemo: ForwardIndex { private var _myIndex = 0 init(index: Int) { _myIndex = index; } func successor() -> ForWardIndexDemo { return ForWardIndexDemo(index:_myIndex++) } }
The type associated with the collection, IndexType, indicates which type is used to index the collection. Any type that implements ForwardIndex can be used as an IndexType.
ForwardIndex is an index that can only be increased, for example, a forward index of 0 can be increased to 1,2,3, etc., this protocol is internally inherited from Equatable and _Incrementable protocols. To adhere to the ForwardIndex () protocol successor -> Self and Equableable protocols must be implemented.
Read more about it here.
source share