回答編集履歴
1
すぺるみす
answer
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
in Swift
|
4
4
|
```swift
|
5
|
-
struct
|
5
|
+
struct Stamp {
|
6
6
|
|
7
|
-
enum
|
7
|
+
enum StampType {
|
8
8
|
case a
|
9
9
|
case b
|
10
10
|
case failure
|
11
11
|
}
|
12
12
|
|
13
13
|
let date: Int
|
14
|
-
let type:
|
14
|
+
let type: StampType
|
15
15
|
|
16
|
-
init?(date: Int, type:
|
16
|
+
init?(date: Int, type: StampType) {
|
17
17
|
|
18
18
|
guard case 0..<7 = date else {
|
19
19
|
|
@@ -25,7 +25,7 @@
|
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
|
-
extension
|
28
|
+
extension Stamp: CustomStringConvertible {
|
29
29
|
|
30
30
|
var description: String {
|
31
31
|
switch self.type {
|
@@ -36,9 +36,9 @@
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
struct
|
39
|
+
struct RandomStampType: Sequence, IteratorProtocol {
|
40
40
|
|
41
|
-
func next() ->
|
41
|
+
func next() -> Stamp.StampType? {
|
42
42
|
|
43
43
|
switch arc4random_uniform(3) {
|
44
44
|
case 0: return .a
|
@@ -49,8 +49,8 @@
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
|
52
|
-
zip(Array(0..<7),
|
52
|
+
zip(Array(0..<7), RandomStampType())
|
53
|
-
.flatMap {
|
53
|
+
.flatMap { Stamp(date: $0.0, type: $0.1) }
|
54
54
|
.forEach { print($0) }
|
55
55
|
|
56
56
|
```
|