teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

エラーの件を追記しました

2017/03/27 07:30

投稿

apple2
apple2

スコア37

title CHANGED
File without changes
body CHANGED
@@ -20,13 +20,13 @@
20
20
  }
21
21
 
22
22
 
23
- //こんな風にしたい
23
+ //こんな風にしたいのですが
24
24
  func say(_ i: Int){
25
- let arr = [label_001,label_002,label_003,label_004]
25
+ let arr = [label_001,label_002,label_003,label_004] as [Any]
26
- arr[i].text = "this is 00" + String(i)
26
+ ( arr[i] as AnyObject).text = "this is 00" + String(i)
27
27
  }
28
28
 
29
29
  _ = say(1)
30
30
 
31
-
32
- ```
31
+ ```
32
+ Type 'Any' does not conform to protocol 'AnyObject' こういうエラーが出ます

1

たくさんの部品があるときに、その名前を直接書くんじゃない方法が知りたいんです

2017/03/27 07:30

投稿

apple2
apple2

スコア37

title CHANGED
File without changes
body CHANGED
@@ -13,9 +13,9 @@
13
13
 
14
14
  switch i {
15
15
  case 1: label_001.text = "this is 001"
16
- case 2: label_001.text = "this is 002"
16
+ case 2: label_002.text = "this is 002"
17
- case 3: label_001.text = "this is 003"
17
+ case 3: label_003.text = "this is 003"
18
- case 4: label_001.text = "this is 004"
18
+ case 4: label_004.text = "this is 004"
19
19
  default : break
20
20
  }
21
21