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)
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

OptionalsのリストにAssertJ

分類Dev

作曲のJava 8 Optionals

分類Dev

Create a multidimensional generic array of Optionals

分類Dev

Is it possible to return first not null value for different Java types with Optionals?

分類Dev

Swift: why do I need optionals anyways?

分類Dev

When to use unwrapped optionals as part of a type definition

分類Dev

Synchronizing very fast threads

分類Dev

Non-optional expression of type 'AnyObject' used in a check for optionals

分類Dev

Fast group rank() function

分類Dev

Enumeration class in physical data model

分類Dev

Fast greedy on graph objects

分類Dev

Create empty enumeration of given Type

分類Dev

Fast sorted sample with replacement

分類Dev

Sorting an array of enumeration

分類Dev

Unexpected NullPointException with RxKotlin when mapping optionals

分類Dev

How to Intercept Property Enumeration of an Object?

分類Dev

Array Enumeration Not Working Properly?

分類Dev

Enumeration in C

分類Dev

LaTeX in the web (equations enumeration)

分類Dev

for-in(Objective-C Fast Enumeration)in for-in

分類Dev

Enumeration of EF stored procedure results

分類Dev

How to cast pointer value to enumeration?

分類Dev

Array<T> extension to filter and unwrap optionals

分類Dev

unwrapping optionals in swift

分類Dev

enumeration in python for the combinations

分類Dev

Swift Optionals vs. Ruby ||=

分類Dev

Consistent enumeration of a btattached controller

分類Dev

Unwrap optionals in for statement

分類Dev

Swift IOSFacebookログインFast-App-Switch