Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- struct Photo {
- let no: Int
- let name: String
- }
- struct PhotoAlbum: Collection, Sequence, IteratorProtocol {
- var photos: [Photo]
- var startIndex = 0
- var currentIndex = 0
- var endIndex: Int {
- return photos.count + 1
- }
- subscript(position: Int) -> Photo {
- return photos[position]
- }
- mutating func next() -> Photo? {
- defer { currentIndex += 1 }
- return photos[count]
- }
- func index(after i: Int) -> Int {
- return count + i
- }
- }
- let photoAlbum = [Photo(no: 1, name: "sea"), Photo(no: 2, name: "mountain")]
- var albumIterator = photoAlbum.makeIterator()
- print(albumIterator.next()?.name)
Add Comment
Please, Sign In to add comment