MVVM with Combine Tutorial for iOS | raywenderlich.com

I never saw an awkward and failed tutorial like this on this web site.

Also, Sample project is not working. !!!

The problem has been pointed out. The AnyCancellable for the city publisher needs to be retained. The subscription to the $city publisher exists only within the scope it was created in. i.e. the init method. you need private var citySubscription: AnyCancellable? below the the disposables var in the WeeklyWeatherViewModel. and then in the init change _ = $city… to citySubscription = $city

I am sorry if this is a very amateur comment, but I’ve been trying to type code by code to learn based on the starter project, and I stumble upon a roadblock and I’ve been really troubled by it.
Yes I could’ve just copy and pasted but I really want to learn how to type the return session.dataTaskPublisher snippet in " Building the App" section for forecast().

Firstly, there is a compilation error when I was typing mapError where it won’t autocomplete .network. May I know why is that, in that case if I am doing this on my own how would i think of using .network().

Secondly, the autocompletion for flatMap is
(maxPublishers: <#T##Subscribers.Demand#>, <#T##transform: ((data: Data, response: URLResponse)) → Publisher##((data: Data, response: URLResponse)) → Publisher#>)
However, in the example, in the closure block there is only one variable declared being pair, how does that work?

Also, is there any way to let XCode escape to
.flatMap(maxPublishers: .max(1)) { pair in
decode(pair.data)
}
when using tab autocompletion will just bring me to the 2nd variable (<#(data: Data, response: URLResponse)#>) → Publisher in inside the function.

Sorry for the poorly worded and phrased question as well, but I will really appreciate this reply

I’m about a week into Swift, Use to be a webdev (Vue, React etc…)

Seeing this Tutorial, I really get that Swift UI is just a swift version of react. Seems like it would have better performance though …

Yeah, the code as-is will not work because it needs to store the cancelables.

Could someone at RW please update the init() code with .store(in: &disposables)?

I was losing my mind on this for some time until I realized that RW has a comments section. I kept thinking I missed some critical line of code.

Since this is one of the first post-hello-world tutorials that comes on Google for terms involving “swiftui”, I have to wonder how many other people like me are running into the same issue

OMG, thanks for this. You saved me significant time. One would assume that there is a process at RW where authors always ensure tutorial projects are still working whenever a new stable version of Xcode is released (especially in the case of paying tutorials). I downloaded this tutorial’s resources only today and the bug is still there.

There are more serious bug in this app.
If you try such city as Moscow, Murmansk, Basel, Clyde River or Sisimiut ( where snow), you won’t see anything.
Because of incomplete enumMainEnum:

enum MainEnum: String, Codable {
case clear = "Clear"
case clouds = "Clouds"
case rain = "Rain"
}

You need something like this:

enum MainEnum: String, Codable {
case clear = "Clear"
case clouds = "Clouds"
case rain = "Rain"

case snow = "Snow"
case drizzle = "Drizzle"
case thunderstorm = "ThunderStorm"
case mist = "Mist"
case smoke = "Smoke"
case haze = "Haze"
case dust = "Dust"
case fog = "Fog"
case sand = "Sand"
case ash = "Ash"
case squall = "Squall"
case tornado = "Tornado"
}

Or after some time you suddenly stop receiving information.
Probably, it’s a bad idea to use enum in Codable Model:

struct Weather: Codable {
    let main: MainEnum
   let weatherDescription: String
}

Better to use String?

"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}]
"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}]
"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}]

And YES, buggy tutorial’s resources are still here.

@rperes Can you please help with this when you get a chance? Thank you - much appreciated! :]

There is also a leak in the project (or perhaps SwiftUI ), multiple instances of CurrentWeatherViewModel are created.

@rperes Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hello there!

Thank you very much for the tutorial!

Couple of things tho, which might be only connected to the latest XCode release (12.0.1), but happening both if you follow the tutorial or run the final project:

  1. The app is crashing when opening up current weather for a city (try London, on my machine reproducable 100% after opening current weather view 2-3 times)

  2. There is something wrong with rendering CurrentWeatherView, when you open it you can see that all the UI elements are off and move to a correct position after a moment.

  3. For some reason there is no animation applied to instances of List, while in the tutorial on the gifs there is a standard animation for tables.

Would appreciate any feedback on these!

Really enjoyed this tutorial! Thank you!

I was very excited when I saw the title of this tutorial, because I am starting to learn Combine as well as MVVM. I was quickly buried in the exponential abstraction upon abstraction and got completely lost as to what we were doing and why. I am greatly disappointed in the software development industry’s complete inability to break things down into bite-sized pieces. It seems like people love, or are used to, cramming as much as they can into each step in ways that are dizying. Teasing them apart to try and follow along is many times impossible. I would love to see another version of this, or future version of tutorials, that focus on the end goal being to help others learn as opposed to a demo of some smart person being able to create something using some tech tools. Is the point of these tutorials not to help teach others? I get it that every learns differently and some wiz kids out there will read this, feel like the author is one of their people, and love it. But I can tell you that, as a hands-on, one-step-at-a-time learner, this tutorial did nothing but disappoint me. I gained nothing new from this. Please consider your audiences, your goals for them, and if your goal is to help others learn, and not just show what you can do, then see how you can find out if they were able to glean anything from what and how you taught.

1 Like

Their API must have changed. You can fix it a couple of ways.
In the Responses.swift - it has to do with the:

enum MainEnum: String, Codable {
case clear = “Clear”
case clouds = “Clouds”
case rain = “Rain”
}

If there’s a case that is not listed, like “Snow”, then the decoding the JSON for the response will fail.

I would prefer - don’t use the MainEnum.

Change:
struct Weather: Codable {
let main: String

Then you just have to remove the rawValue on
var fullDescription: String {

guard let description = item.weather.first?.weatherDescription.localizedCapitalized else { return “” }

return description

}
in the DailyWeatherRowViewModel. It’s a string anyway - safer not to hard code???

I have faced this issue, too, and I have just finded out the problem/solution:
the code is ok… I think that you are working with the simulator without showing the keyboard on it. This makes that, if you don’t press the Intro key in the simulator keyboard, you don’t resign the first responder and the focus still remains in the textfield. So the solution is just to simulate the project introducing the text in the search field by the simulator keyboard (or real device with a real keyboard ;)) and press the intro key to dismiss the keyboard.
Wish help you all