DC iOS: SwiftUI Architecture and Best Practices

Поделиться
HTML-код
  • Опубликовано: 20 янв 2025

Комментарии • 34

  • @PeteSchuette
    @PeteSchuette 3 месяца назад

    At first I was concerned about organization, but by the end of it, I completely agree. Great talk.

    • @PeteSchuette
      @PeteSchuette 3 месяца назад +1

      Mayyybe a slight disagreement on some of the testing strategies, but that's minor

  • @withniyaz
    @withniyaz 10 месяцев назад

    Never knew i was doing the exact way how Azam did and thought myself it was wrong until watching this video. Great talk ❤

    • @jackdanyal4329
      @jackdanyal4329 3 месяца назад

      if he said smth doesn't mean it's the correct way :) this approach will not work in really big projects :) in small ones - sure, in big ones, oh boy. just switch on your common sense.

  • @wonton120
    @wonton120 Год назад +5

    For iOS 17 and the new Observation framework, this pattern will make sense. Also, for iOS17, the view will not be reloaded unless the view got changed.

  • @trendz4422
    @trendz4422 11 месяцев назад

    48:00 We can't run tests in parallel in this case, right?

    • @RiccardoMontagnin
      @RiccardoMontagnin 11 месяцев назад

      You can actually use an in-memory database that is created with each test run. But if you use a real database, then yeah. In this case it's better to just mock the database

  • @pengwei4872
    @pengwei4872 11 месяцев назад

    Great talk! This is so similar to modern react, which is great!

  • @davidlangley9287
    @davidlangley9287 Год назад +15

    This feels so wrong to me, it's like going back to the beginning but instead of having massive view controllers, we now have massive... views???
    For small personal projects or tutorials (like the ones you showed from Apple), this should be enough. But in real world applications where many developers are working in one app, this pattern won't let each other to safely edit a complex view. We use automatic tests for view models AND views because many developers might be working on a single view/feature, we can't just test manually or use xcode previews... anyways

    • @azamsharp
      @azamsharp Год назад +1

      If you views are getting bigger then divide them into smaller views.

    • @RomanRomanov1441
      @RomanRomanov1441 11 месяцев назад +2

      You are totally right and we should never forget that Apple's suggestions in usage of their frameworks are good only for a 3 screens todo app. And thus should be ignored in favor of SOLID principles.

    • @trendz4422
      @trendz4422 11 месяцев назад +2

      Answer for Bigger apps at 28:00

    • @RahulDhiman-c1n
      @RahulDhiman-c1n Месяц назад

      what feels right to you. Please also explain?
      How would we use Fetch request or Environments?
      How Child views are going to use the shared Data?
      @davidlangley9287

  • @jdotseven
    @jdotseven Год назад

    I like the thinking behind your presentation - have to consider it in the future. What are you using to align the closing braces visually?

  • @mohammedrokonuddin7153
    @mohammedrokonuddin7153 Год назад +2

    Hi Azam, thank you for your beautiful SwiftUI Architecture and Best Practices talk. I have a question though. In the 50 minutes of Count example, you mentioned view whose state property doesn't change, it doesn't get recreated but rather reevaluated. But I tried setting random colors to Text. Every time when I press the Increament button the count increases and also color of Counter changes even though it is a static text. Can you explain that?

    • @azamsharp
      @azamsharp Год назад

      Code example?

    • @mohammedrokonuddin7153
      @mohammedrokonuddin7153 Год назад

      @@azamsharp
      struct ContentView: View {
      @State var count = 0
      var body: some View {
      let _ = Self._printChanges()
      VStack {
      Image(systemName: "globe")
      .imageScale(.large)
      .foregroundStyle(.random)
      Text("Counter")
      .font(.largeTitle)
      .foregroundStyle(.random)
      Text("\(count)")
      Button("Increment") { count += 1 }
      .frame(width: 124, height: 32)
      .tint(.random)
      .background(.random)
      }
      }
      }
      extension ShapeStyle where Self == Color {
      static var random: Color {
      Color(
      red: .random(in: 0 ... 1),
      green: .random(in: 0 ... 1),
      blue: .random(in: 0 ... 1)
      )
      }
      }

    • @mohammedrokonuddin7153
      @mohammedrokonuddin7153 Год назад

      But if I refactor the code to following, it works fine:
      struct ContentView: View {
      @State var count = 0
      var body: some View {
      let _ = Self._printChanges()
      VStack {
      AnotherView()
      .background(.random)
      Text("\(count)")
      Button("Increment") { count += 1 }
      .frame(width: 124, height: 32)
      .tint(.random)
      .background(.random)
      }
      }
      }
      struct AnotherView: View {
      var body: some View {
      Image(systemName: "globe")
      .imageScale(.large)
      .foregroundStyle(.random)
      Text("Counter")
      .font(.largeTitle)
      .foregroundStyle(.random)
      }
      }
      extension ShapeStyle where Self == Color {
      static var random: Color {
      Color(
      red: .random(in: 0 ... 1),
      green: .random(in: 0 ... 1),
      blue: .random(in: 0 ... 1)
      )
      }
      }

    • @azamsharp
      @azamsharp Год назад

      @@mohammedrokonuddin7153 The .random gets called during evaluation and the view gets redrawn.

  • @pe60t0
    @pe60t0 Год назад +8

    "I am going to test this manually" lost me :D

    • @azamsharp
      @azamsharp Год назад +2

      I personally invest my time on writing tests for the domain logic.

    • @shakil807g
      @shakil807g Год назад

      Exactly!! lol "I am going to test this manually"

  • @HumanoidTyphoon91
    @HumanoidTyphoon91 5 месяцев назад +6

    One important caveat to this approach, he based it on his experience creating 200 prototypes in a couple of years... That leaves you with very low complexity per each app, so what he says indeed makes sense in that context, but if you are a team of 15 devs working on a single complex app, that's a different scenario completely, and his advice for large apps are not battle tested, he just thinks it will probably work...

  • @islamISHere_001
    @islamISHere_001 Год назад

    great video
    thank you

  • @VinoKanan
    @VinoKanan 10 месяцев назад

    Can you please talk about The Composable Architecture.

  • @gogugigi85
    @gogugigi85 Год назад +5

    Nice approach, not applicable in big projects also remind me the masive view controller and seems too permisive to where business logic resides, not so good for clarity on big projects, tutorial projects will be fine.

    • @azamsharp
      @azamsharp Год назад +1

      On the contrary, I have completed several very large projects using this approach and it worked out very well. We were able to reduce at least 40% of the code by not creating VM for every single screen. Less code is always better.

    • @gogugigi85
      @gogugigi85 Год назад +4

      @azamsharp how exactly it reduces 40% the code, the business logic is just moved somewhere else, if is not in the VM it in a Reducer or Presenter or Model or in the View(which is the worst), and in most cases when the business logic is not where expected it reduces code clarity. I have my concerns that this can be applied in large projects and improve the project.

    • @pe60t0
      @pe60t0 Год назад

      Also why “less code is always better” this is so wrong

  • @narencool236
    @narencool236 8 месяцев назад

    We can create whole app in single file but that does not mean we should, same way we can write whole logic in view class sill it will work that does not mean we should

  • @praveenvelanati9450
    @praveenvelanati9450 7 месяцев назад +2

    Test manually lol :). This is not a good practice