Created
December 22, 2016 18:59
-
-
Save alexaubry/f1f725ecce79756c2991b47b8cdaef0a to your computer and use it in GitHub Desktop.
Extension on the CFArray type to make it conform to Sequence
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
/* | |
* CFArray+Sequence.swift | |
* Alexis Aubry Radanovic | |
*/ | |
import Foundation | |
import CoreFoundation | |
extension CFArray: Sequence { | |
public func makeIterator() -> Iterator { | |
return Iterator(self) | |
} | |
public struct Iterator: IteratorProtocol { | |
var array: NSArray | |
var idx = 0 | |
init(_ array: CFArray){ | |
self.array = array as NSArray | |
} | |
public mutating func next() -> Any? { | |
guard idx < array.count else { return nil } | |
let value = array[idx] | |
idx += 1 | |
return value | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!