ios - Swift test if type is collection -


i'm busy trying write recursive method. there no explicit 'children', collections, i'd checking if can iterate on property.

i've seen people find swift.array<string>, increase number of types need test for.

should try cast , obtain count?


class childarray : nsarray { } 

you can take advantage of toll-free bridging between swift , objective-c. objects in objc have iskindofclass method identify if descend class:

class childarray : nsarray { }  func iscollectiontype(value : anyobject) -> bool {     let object = value as! nsobject      return object.iskindofclass(nsarray) }  var arrayofint = [1, 2, 3] var myarray = childarray() var anint = 42  println(iscollectiontype(arrayofint)) // true println(iscollectiontype(myarray))    // true println(iscollectiontype(anint))      // false 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -