So I'm very new to swift so I might be getting this all wrong.
I'm learning to work with combine so I used the playground to log at an interval like so
var cancellable:AnyCancellable? = Timer.publish(every: 1, on: .main, in: .default) .autoconnect() .sink { print($0) } PlaygroundPage.current.needsIndefiniteExecution = true It's very simple and it works like I expect it to, printing a log every second.
Now when I create a new iOS project in Xcode it doesn't seem to work and I can't figure out why. From a blank project, I simply added this in the ContentView
struct ContentView: View { func test() { var cancellable: AnyCancellable? cancellable = Timer.publish(every: 1, on: .main, in: .default) .autoconnect() .sink { print($0) } } var body: some View { VStack { Text("Hello, world!") .padding() } } init() { test() } } All of a sudden, it doesn't work and the log won't print. I'm sure it's something dumb that I'm not understanding but I've been looking at this forever now. My real case is with a network call that is not running so I tried simplifying as much as I can and this is as simple as I could get.
Any help appreciated!
Thanks!