swift - Iterating over an NSOrderedSet -
i'm trying iterate on instance of nsorderedset. this:
func myfunc() { var orderedset = nsorderedset(array: [ 42, 43, 44]) n in orderedset { nslog("%i", n) } }
...however loop line produces compiler error:
'nsorderedset' not have fellow member named 'generator'
now convert array this:
n in orderedset.array { nslog("%i", n) }
...but wondered if there improve solution?
i'm keen understand why it's possible iterate on set not ordered set? nsorderedset
implements nsfastenumeration
, should work right?
you can iterate on ordered set with
let orderedset = nsorderedset(array: [ 42, 43, 44]) orderedset.enumerateobjectsusingblock { (elem, idx, stop) -> void in println("\(idx): \(elem)") }
update: of swift 1.2 (xcode 6.3), nsorderedset
conforms sequencetype
, can enumerated for ... in ...
:
let orderedset = nsorderedset(array: [ 42, 43, 44]) elem in orderedset { println(elem) }
swift nsorderedset
No comments:
Post a Comment