-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathbitwise_takable.swift
73 lines (63 loc) · 1.4 KB
/
bitwise_takable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
public protocol Reporter {
func report() -> String
}
public class Subject {
public var value = 1
public init(_ v: Int) {
value = v
}
}
public var s2 = Subject(2)
public var s3 = Subject(3)
public var s4 = Subject(4)
public var s5 = Subject(5)
public struct Container : Reporter {
#if BEFORE
var v : Subject
#else
weak var v : Subject?
#endif
public init(_ s: Subject) {
v = s
}
public func report() -> String{
#if BEFORE
return "Container(\(v.value))"
#else
return "Container(\(v!.value))"
#endif
}
}
public func createContainerReporter() -> Reporter {
return Container(s2)
}
public struct PairContainer: Reporter {
public var pair : (Container, Container)
public init(_ p : (Container, Container)) {
pair = p
}
public func report() -> String {
return "PairContainer(\(pair.0.report()), \(pair.1.report()))"
}
}
public func createPairContainerReporter() -> Reporter {
return PairContainer((Container(s3), Container(s4)))
}
public enum EnumContainer : Reporter {
case Empty
case Some(Container)
public func report() -> String {
switch self {
case .Empty:
return "EnumContainer Empty"
case .Some(let c):
return "EnumContainer(\(c.report()))"
}
}
}
public func createEnumContainerReporter() -> Reporter {
return EnumContainer.Some(Container(s5))
}
public func report(_ r: Reporter) -> String {
return r.report()
}