Reactive Programming in iOS with Combine

Feb 4 2021 · Swift 5.3, macOS 11.0, Xcode 12.2

Part 3: Combining Operators

17. Challenge: Append and Prepend

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 16. Append Next episode: 18. More Combining Operators

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You’ve learned all about Prepending and Appending operators - so now it’s time for a challenge. Back in the day, phone numbers used to be a lot easier to remember! 7 digits (in the United States, at least) was all you needed to remember to call your best friend. Now you need area codes, and if you’re calling a business, you’ll probably need to know a person’s extension, and if the number was long distance, you’d need to prepend a “1” in front of it. So for this challenge:

example(of: "Making Phone Numbers") {

  let phoneNumbersPublisher = ["123-4567"].publisher
  let areaCode = "410"
  let phoneExtension = "901"

  phoneNumbersPublisher
    .prepend("1-", areaCode, "-")
    .append(" EXT ")
    .append(phoneExtension)
    .collect()
    .sink(receiveValue:
    {
      print($0.joined())
    })
    .store(in: &subscriptions)
}