This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let keyboardWillOpen = NotificationCenter.default | |
| .publisher(for: UIResponder.keyboardWillShowNotification) | |
| .map {$0.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect} | |
| .map {$0.height} | |
| let keyboardWillHide = NotificationCenter.default | |
| .publisher(for: UIResponder.keyboardWillHideNotification) | |
| .map { _ in CGFloat(0)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let germanCities = PassthroughSubject<String, Never>() | |
| let italianCities = PassthroughSubject<String, Never>() | |
| let europianCities = Publishers.Merge(germanCities, italianCities) | |
| _ = europianCities.sink(receiveValue: { city in | |
| print("\(city) is a city in europe") | |
| }) | |
| germanCities.send("Munich") | |
| germanCities.send("Berlin") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _ = Publishers.Sequence(sequence: [1,2,2,3,3,4,7]) | |
| .map { $0 * 2 } | |
| .flatMap { Publishers.Just($0) } | |
| .filter { $0.isMultiple(of: 2) } | |
| .dropFirst(3) | |
| .removeDuplicates() | |
| .sink(receiveValue: { value in | |
| print(value) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _ = Publishers.Sequence(sequence: [1,2,4]) | |
| .map { $0 * 10 } | |
| .flatMap { Publishers.Just($0) } | |
| .sink(receiveValue: { | |
| print($0) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let subject = PassthroughSubject<String, Never>() | |
| let publisher = subject.eraseToAnyPublisher() | |
| let subscriber1 = publisher.sink(receiveValue: { value in | |
| print(value) | |
| }) | |
| //subscriber1 will recive the events but not the subscriber2 | |
| subject.send("Event1") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let subject = PassthroughSubject<String, Never>() | |
| let publisher = subject.eraseToAnyPublisher() | |
| let subscriber = publisher.sink(receiveValue: { value in | |
| print(value) | |
| }) | |
| subject.send("Combine") //The Subscriber will print "Combine" | |
| subject.send("Swift") //The Subscriber will print "Swift" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let subscriber = publisher.sink(receiveCompletion: { _ in | |
| print("finished") | |
| }) { value in | |
| print(value) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let publisher = Publishers.Just("Combine Swift") | |
| let subscribtion = publisher.sink { value in | |
| print(value) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let publisher = Publishers.Just("Combine Swift") | |
| let sequencePublisher = let publisher = Publishers.Sequence(sequence: [1,2,3,5,6]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol DisountStrategy { | |
| func presentDiscountMessage() | |
| } | |
| struct NoDiscountStrategy: DisountStrategy { | |
| //Provides handling for non discount case | |
| } | |
| struct DefaultDiscountStrategy: DisountStrategy { | |
| //Provides handling for discount case |