What is the difference between SequenceType and CollectionType in swift?

GeneratorType (IteratorProtocol in Swift 3): Generators is something that can give the next element of some sequence, if there is no element it returns nil. Generators encapsulates iteration state and interfaces for iteration over a sequence.

A generator works by providing a single method, namely – next(), which simply returns the next value from the underlying sequence.

Following classes Adopt GeneratorType Protocol:

DictionaryGenerator, EmptyGenerator, more here.


SequenceType (Sequence in Swift 3): A Sequence represent a series of values. Sequence is a type that can be iterated with a for...in loop.

Essentially a sequence is a generator factory; something that knows how to make generators for a sequence.

Following classes Adopt SequenceType Protocol:

NSArray, NSDictionary, NSSet and more.


CollectionType (Collection in Swift 3): Collection is a SequenceType that can be accessed via subscript and defines a startIndex and endIndex. Collection is a step beyond a sequence; individual elements of a collection can be accessed multiple times.

CollectionType inherits from SequenceType

Following classes Adopt CollectionType Protocol:

Array, Dictionary, Set, Range and more.


Form more information you can see this, this, and this

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.