Hi community ! I almost have completed task for the position Junior IOS , but

I have a black holes in my code , i have finished it with help of my friend …so i need to disassemble my project step by step ,line by line to finalise my meagre knowledge

Please , go with me throw the project . https://github.com/DimaKozhanovsky/FunnyWeather
Thank you in advance !

Are you asking for someone to provide a code review of your project? Help fix your code? Just demonstrate your project?

Hi ! Thank you for the response ! i have not done it by myself , i mean i do understand how does it work partially :) for example i have been trying to understand how this block of code works

I am trying to understand every line in code . Below , my attempts :sweat_smile:

It’s hard to read images. You can use codeblocks to share and format code.

Type this:

```javascript
code here
```

To get this:

code here

Did you have a specific question? Is there a specific line you don’t understand? Or are you asking someone to go through a codebase and explain each and every line? That’s a pretty big ask!

Project is not big :) i so understand a lot from project , but anyway i do not understand some blocks of code ( like above ) .

import SwiftUI
import UIKit
import Combine

struct NetworkImageView<Placeholder: View, ProgressBlock: View>: View {
   // Here we describe 2 generics Placeholder and ProgressBlock and subscribe them to the view protocol so that we can put everything that conforms to the View protocol for reusability
   
   @Environment(\.horizontalSizeClass) var horizontalSizeClass
   //@Environment It is needed to understand the user settings and adapt the code to them
   // In SwiftUI, we can switch between a HStack and VStack based on the horizontalSizeClass that we get from the @Environment:
   @StateObject var viewModel: ImageViewModel
   //@StateObject makes sure that only one instance is created per a view structure. This enables us to use @StateObject property wrappers for class type view models which eliminates the need of managing the view model’s lifecycle ourselves.
   

   
   let placeholder: Placeholder
   let progressBlock: ProgressBlock
   //In the constants above, you can put everything that is subscribed to the View protocol
   
   init(
       //In Swift, an initializer is a special function that we use to create objects of a particular class, struct, or enum. Initializers are sometimes called constructors because they "construct" objects.
       imageUrlString: String,
       
       @ViewBuilder placeholder: () -> Placeholder,
       @ViewBuilder progressBlock: () -> ProgressBlock
   ) {
       
       _viewModel = .init(wrappedValue: ImageViewModel(imageUrlString: imageUrlString))
           //_viewModel
      // designate private variables , a view model is created, and the view subscribes to its changes,
                // this is how you initialize @StateObject, this is its initializer, look towards @properyWrapper, how it works
   
       self.placeholder = placeholder()
       self.progressBlock = progressBlock()
   }
   
   var body: some View {
       ZStack {
           switch viewModel.state {
           case .loading:
               progressBlock
           case .error:
               placeholder
           case .success(let image):
               Image(uiImage: image)
                   .resizable()
           }
       }
   }
}

What about that block don’t you understand? Is there a specific line? A comment? The goal?

The first three lines import libraries. It then defines a struct/class with an init, instance vars, and a body which returns a view.

what type of data has progressBlock ? What is flow of data between this code any other parts of the project ?

The comments say it’s a generic which is subscribed to the View protocol. That means, it can be type which implements the View functions.

You’d want to search the rest of the code for this object name to see where this object is used. The shared snippet accesses the View calls on the data passed in, which may trigger any other parts which implement those functions.

1 Like