Using swift dev toolchain with SwiftUI/Combine

Is it possible to use current master toolchain (13 October snapshot) in development SwfitUI/Combine apps?
I try to use this toolchain, but several compilation errors occurred.

Just(42).debounce(for: 0.5, scheduler: DispatchQueue.main)
// error: Argument type 'DispatchQueue' does not conform to expected type 'Scheduler'
// error: Cannot convert value of type 'Double' to expected argument type 'DispatchQueue.SchedulerTimeType.Stride'

Just(Data()).decode(type: Int.self, decoder: JSONDecoder())
// error: Cannot invoke 'decode' with an argument list of type '(type: Int.Type, decoder: JSONDecoder)'

let url = URL(string: "url")!
URLSession.shared.dataTaskPublisher(for: url)
// error: Value of type 'URLSession' has no member 'dataTaskPublisher'

Also fatal error in runtime

Fatal error: Call of deleted method

I'm a little unsure what you mean by "current master toolchain". I assume you mean Xcode 11.2 beta 2 (11B44) which was released on 11 October. If so, you can definitely use it to develop SwiftUI/Combine apps.

Looking at your samples provided:

  • I'm not sure what you're importing. That might be part of your issues.
  • You should always keep a reference to your publishers or they will be deinit'd immediately.
  • For the debounce example, you are specifying the wrong type of argument for "for:"

I've cleaned things up a bit, this works for me in the 11B44 build in a playground. I only really changed the debounce example though.

import Combine
import Foundation

let justDebouce = Just(42)
  .debounce(for: .seconds(0.5), scheduler: DispatchQueue.main)
  .sink { print("Received Debounce: '\($0)'")}

let justDecode = Just(Data())
  .decode(type: Int.self, decoder: JSONDecoder())
  .sink(
    receiveCompletion: { print("Received Decode Complete: '\($0)'") },
    receiveValue: { print("Received Decode : '\($0)'") })

let url = URL(string: "http://apple.com/")!
let task = URLSession.shared.dataTaskPublisher(for: url)
  .sink(
    receiveCompletion: { print("Received Task Complete: '\($0)'") },
    receiveValue: { print("Received Task : '\($0)'") })

Of course, the debounce won't emit anything as Just emits it's value and then completes. There won't be any opportunity for anything to be debounced.

And the decode will fail when provided with just an empty Data().

He means https://swift.org/download/#snapshots

2 Likes

I know how to use Publishers. It is only examples of compiler errors.
And I meant swift toolchain from https://swift.org/download/#snapshots

Terms of Service

Privacy Policy

Cookie Policy