9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Swift]AnyObject型の配列からString型の値だけ抜き出す方法

Last updated at Posted at 2014-12-24

俺の名はケンヤ。難事件をいくつも迷宮入りさせたニート。しかし ある時謎の組織入社し薬を飲まされ身体が縮んで Braian になっちゃった。

詰まったのでメモ残します〜

var k: AnyObject = []
var array: [AnyObject] = ["abc", 1, "def", 2, "ghi", 3]

for (var i = 0; i < array.count; i++) {
    if let string = array[i] as? String {
        k.append(string)
    }
}
println(k)
//["abc", "def", "ghi"]
9
10
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?