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

質問編集履歴

1

項目の整理 文言追加

2019/02/25 03:07

投稿

shsw228
shsw228

スコア20

title CHANGED
File without changes
body CHANGED
@@ -1,36 +1,30 @@
1
- 現在APIを叩いて返ってきた値を使ってUITableViewで表示するアプリを書いています。返り値は以下のようになっています。
1
+ 現在APIを叩いて返ってきた値を使ってUITableViewで表示するアプリを書いています。Alamofireのresponse.result.valueで取得できる値は以下のようになっています。
2
2
 
3
3
  ```json
4
- [{
5
- "項目1" : "aaa"
4
+ [{"created_at" : "aaa"
6
- "項目2" : "bbb"
5
+ "author" : "bbb"
7
- "項目3" : "ccc"
6
+ "score" : "ccc"
8
7
 
9
8
  },{
10
- "項目1" : "aaa"
9
+ "created_at" : "aaa"
11
- "項目2" : "bbb"
10
+ "author" : "bbb"
12
- "項目3" : "ccc"
11
+ "score" : "ccc"
13
12
  }]
14
13
  ```
15
14
 
16
15
  DataModelを作成して代入するところが以下のようになっています。
17
16
  ```swift
18
- func getCellData(json:JSON){
17
+ func getCellData(json:JSON){
19
18
  if let postedDateUnixTime = json[0]["created_at"].string {
20
- postedDataModel.postedDate = postedDateUnixTime
21
19
  postedDataModel.postedBy = json[0]["author"].stringValue
22
20
  postedDataModel.scoreNumber = json[0]["score"].stringValue
23
- postedDataModel.sourceNumber = json[0]["source"].stringValue
24
- postedDataModel.tags = json[0]["tags"].stringValue
25
- postedDataModel.rate = json[0]["rating"].stringValue
26
- postedDataModel.rateIconName = postedDataModel.updateRateIcon(rate: postedDataModel.rate)
27
21
  print(postedDataModel.postedBy)
28
- }
22
+ }
29
23
  else{
30
24
  print("API unavailable")
31
25
  }
32
- }
26
+ }
33
- }
27
+
34
28
  ```
35
29
 
36
30
  ---