Skip to content

Instantly share code, notes, and snippets.

@alexisakers
Created December 22, 2016 18:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexisakers/f1f725ecce79756c2991b47b8cdaef0a to your computer and use it in GitHub Desktop.
Save alexisakers/f1f725ecce79756c2991b47b8cdaef0a to your computer and use it in GitHub Desktop.
Extension on the CFArray type to make it conform to Sequence
/*
* 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
}
}
}
@timleg002
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment