swift fast enumeration of optionals

user965972

Is there are better way to do this? Something that looks nicer syntax wise?

let a : [Any] = [5,"a",6]
for item in a { 
  if let assumedItem = item as? Int {
     print(assumedItem) 
  } 
}

Something like this, but then with the correct syntax?

  for let item in a as? Int { print(item) }
ABakerSmith

If you're using Swift 2:

let array: [Any] = [5,"a",6]

for case let item as Int in array {
    print(item)
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related