回答編集履歴
3
first
test
CHANGED
@@ -45,3 +45,25 @@
|
|
45
45
|
//=> c
|
46
46
|
|
47
47
|
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
# first版
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
こっちの方がいいかも。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```swift
|
60
|
+
|
61
|
+
let searchId = 12
|
62
|
+
|
63
|
+
let temp = (x.first {$0["id"] as? Int == searchId} ?? [:])["name"] ?? "(not found)"
|
64
|
+
|
65
|
+
print(temp)
|
66
|
+
|
67
|
+
//=> a
|
68
|
+
|
69
|
+
```
|
2
Int
test
CHANGED
@@ -27,3 +27,21 @@
|
|
27
27
|
|
28
28
|
|
29
29
|
見つからなかったときは`(not found)`を返します。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
# Int版
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```swift
|
38
|
+
|
39
|
+
let searchId = 38
|
40
|
+
|
41
|
+
let temp = x.filter {$0["id"] as? Int == searchId}.first?["name"] ?? "(not found)"
|
42
|
+
|
43
|
+
print(temp)
|
44
|
+
|
45
|
+
//=> c
|
46
|
+
|
47
|
+
```
|
1
temp
test
CHANGED
@@ -16,7 +16,9 @@
|
|
16
16
|
|
17
17
|
let searchId = "24"
|
18
18
|
|
19
|
-
|
19
|
+
let temp = x.filter {String(describing: $0["id"] ?? "") == searchId}.first?["name"] ?? "(not found)"
|
20
|
+
|
21
|
+
print(temp)
|
20
22
|
|
21
23
|
//=> b
|
22
24
|
|