Skip to content

Commit 1b795b9

Browse files
committed
publisher and subscriber demo
1 parent 25d9fa2 commit 1b795b9

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Combine
2+
3+
/* I hope the video was helpful, please feel free to ask questions and if you are new to the channel then please do subscribe and support the channel by sharing it with your iOS group.
4+
Regards,
5+
Ravi (CodeCat15)
6+
*/
7+
8+
func addTwoNumbers(a: Int, b: Int) -> Int {
9+
a + b
10+
}
11+
12+
let justPublisher = Just(addTwoNumbers(a: 1, b: 2))
13+
14+
let justSubscriber = Subscribers.Sink<Int, Never> { completion in
15+
print(completion)
16+
} receiveValue: { valueFromPublisher in
17+
print("value = \(valueFromPublisher)")
18+
}
19+
20+
//let justSubscriber1 = Subscribers.Sink<Int, Never> { completion in
21+
// print("justSubscriber1 = \(completion)")
22+
//} receiveValue: { valueFromPublisher in
23+
// print("justSubscriber1 = \(valueFromPublisher)")
24+
//}
25+
26+
27+
justPublisher.subscribe(justSubscriber)
28+
//justPublisher.subscribe(justSubscriber1)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>

SwiftUI/Publisher_Subscriber/Pub_Sub.playground/playground.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)