You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/DebuggingTechniques.md
+23-51Lines changed: 23 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,66 +15,37 @@ Below is an example of type-error scenario:
15
15
16
16
```swift
17
17
SignalProducer<Int, NoError>(value:42)
18
-
.on(next: { answer in
18
+
.on(value: { answer in
19
19
return_
20
20
})
21
21
.startWithCompleted {
22
22
print("Completed.")
23
23
}
24
24
```
25
25
26
-
The code above will not compile with the following error on a `print` call `error: ambiguous reference to member 'print'
27
-
print("Completed.")`. To find the actual compile error, the chain needs to be broken apart. Add explicit definitions of closure types on each of the steps:
26
+
The code above will not compile with the following error on the `.startWithCompleted` call `error: cannot convert value of type 'Disposable' to closure result type '()'. To find the actual compile error, the chain needs to be broken apart. Add explicit definitions of closure types on each of the steps:
28
27
29
28
```swift
30
29
let initialProducer = SignalProducer<Int, NoError>.init(value:42)
31
-
let sideEffectProducer = initialProducer.on(next: { (answer: Int) in
30
+
let sideEffectProducer = initialProducer.on(value: { (answer: Int) in
32
31
return_
33
32
})
34
33
let disposable = sideEffectProducer.startWithCompleted {
35
34
print("Completed.")
36
35
}
37
36
```
38
37
39
-
The code above will not compile too, but with the error `error: cannot convert value of type '(_) -> _' to expected argument type '(Int -> ())?'` on definition of `on` closure. This gives enough of information to locate unexpected `return _` since `on` closure should not have any return value.
40
-
41
-
#### Binding `DynamicProperty` with `<~` operator
42
-
43
-
Using the `<~` operator to bind a `Signal` or a `SignalProducer` to a `DynamicProperty` can result in unexpected compiler errors.
The reason is a limitation in the swift type checker - A `DynamicProperty` always has a type of `AnyObject?`, but the `<~` operator requires the values of both sides to have the same type, so the right side value would have to be `AnyObject?` as well, but usually a more concrete type is used (in this example `String`).
60
-
61
-
Usually, the fix is as easy as adding a `.map{ $0 }`.
This allows the type checker to infer that `String` can be converted to `AnyProperty?` and thus, the binding succeeds.
38
+
The code above will not compile too, but with the error `error: cannot convert value of type '(Int) -> _' to expected argument type '((Int) -> Void)?'` on definition of `on` closure. This gives enough of information to locate unexpected `return _` since `on` closure should not have any return value.
68
39
69
40
#### Debugging event streams
70
41
71
42
As mentioned in the README, stream debugging can be quite difficut and tedious, so we provide the `logEvents` operator. In its simplest form:
There also cases, specially with [hot signals][[Signals]], when there is simply too much output. For those, you can specify which events you are interested in:
89
+
There also cases, specially with [hot signals][Signal], when there is simply too much output. For those, you can specify which events you are interested in:
0 commit comments