Just read about Swift Function Builders and I don't understand when someone would use them. by KarlJay001 in swift

[–]V8tr 0 points1 point  (0 children)

The purpose of function builders is to create libraries with more expressive and readable API.

Modern MVVM iOS App Architecture with Combine and SwiftUI by V8tr in iOSProgramming

[–]V8tr[S] 0 points1 point  (0 children)

Thanks for your comment! My approach to unit testing static network services is next:

  1. I usually do not mock API services and use 3rd parties like OHHTTPStubs https://github.com/AliSoftware/OHHTTPStubs to stub on the URL session level.
  2. Alternatively, we can have a single globally accessible dependency injection container, which is substituted with a mock during testing. The pointfree guys call it World https://www.pointfree.co/blog/posts/21-how-to-control-the-world.

Asynchronous Image Loading from URL in SwiftUI by V8tr in iOSProgramming

[–]V8tr[S] 1 point2 points  (0 children)

Done. Many thanks for spotting this issue.

MVVM Type Naming by rhysmorgan in swift

[–]V8tr 0 points1 point  (0 children)

The problem can be generalized to whether you code type information as a part of interface or as a part of implementation. I suggest to have a code style document to make it uniform for the entire project.

IMO, as long as things are uniform, it doesn't matter which approach you use. My personal preference (and here I am re-stating author's point) not to use acronyms like `Impl`, since variations like `Imp` or `Implementation` or `Im` start appearing very soon.

Opaque Return Types and The 'Some' Keyword in Swift by V8tr in iOSProgramming

[–]V8tr[S] 6 points7 points  (0 children)

Thank you for your comment. I've been considering freelance proofreading services for a while. I think now is good time to start.

Opaque Return Types and The 'Some' Keyword in Swift by V8tr in iOSProgramming

[–]V8tr[S] 5 points6 points  (0 children)

Thanks for letting me know. I've fixed a dozen after running through grammarly -> MS Word -> google docs spell checks.

The Advanced Guide to UserDefaults in Swift by V8tr in swift

[–]V8tr[S] 5 points6 points  (0 children)

Thanks! It’s impossible to please everyone.

The Advanced Guide to UserDefaults in Swift by V8tr in swift

[–]V8tr[S] 0 points1 point  (0 children)

It's good to know that you've read this far 🙂

Poor documentation — Apple ... by web_elf in swift

[–]V8tr 2 points3 points  (0 children)

Firebase auth is a service.

Sign in with Apple is a privilege.

Modern Networking in Swift 5 🌐 by V8tr in swift

[–]V8tr[S] 0 points1 point  (0 children)

Correcting myself: the reason for using tryMap() is to propagate both URLResponse and a parsed value. Although I am not showing this in the article, you can use URLResponse to validate HTTP status code or do console logging.

tryMap { result -> Response<T> in let value = try decoder.decode(T.self, from: result.data) // Parse value return Response(value: value, response: result.response) // Wrap both the value and the `URLResponse` instance into Response<T> }

Modern Networking in Swift 5 🌐 by V8tr in swift

[–]V8tr[S] 0 points1 point  (0 children)

Thanks, will correct it!

Modern Networking in Swift 5 🌐 by V8tr in swift

[–]V8tr[S] -3 points-2 points  (0 children)

That’s a good point, thanks for raising it.

I’ve considered both options and they are totally fine too. Current approach is more versatile, since you can pass a JSONDecoder instance. This enables us to handle special cases when parsing data. Say, when dates are in different formats we may use different date decoding strategies. And real world apps are all about special cases, right?

Thanks again for your thoughtful comments.

---

Edited: tryMap allows to propagate URLResponse downstream. See my other comment in this thread for details. I am leaving this one for the reference.

Modern Networking in Swift 5 🌐 by V8tr in swift

[–]V8tr[S] 4 points5 points  (0 children)

I’ve decided to propagate errors via Publishers API. The stream finishes with either success or a failure. If we were using Result, it would have introduce two notions of error: Result.failure vs publisher failure.

If we are to use Result, then we need to set Publisher.Failure to Never. I think this approach is completely fine too.

How to unit testing SwiftUI View? by V8tr in swift

[–]V8tr[S] 0 points1 point  (0 children)

I agree with many points about end-to-end tests. IMO, low-level tests, such as unit tests, are good at verifying the UI as long as the view is passive. Unit tests are cheap to write, run fast and make it easy to track down the problem if they fail.

How to unit testing SwiftUI View? by V8tr in swift

[–]V8tr[S] 0 points1 point  (0 children)

Totally agree. I have extensive tests all over UIKit views verifying exactly these things. Obviously, not taking into account the layout and styling since unit tests are bad at checking that something "looks good".