Post

Replies

Boosts

Views

Activity

Why Store
When developing my code, I have seen people saying I should create a Store (eg: ProductStore) with ObservableObject/Published and inside of it, create functions to call the API (eg: ProductAPI) What's the reason for that ? Thank you
2
0
503
Aug ’21
EnvironmentObject
Checking an existing code, I could see an environmentObject set in my main file. What does it mean ? it means I am creating an instance of my store and making them available for the entire application ? Like a static instance in other languages ? or there is something else ? Thank you, @main struct myApp: App { var myStore = MyStore() var body: some Scene { WindowGroup { ContentView() .environmentObject(myStore)
1
0
415
Aug ’21
Create Instance of class
When instanciating an array of ProductModel, I do this way and everything works fine: @Published var products = [ProductModel]() However If I just want one instance, I have an error: @Published var product = ProductModel() Missing argument for parameter 'from' in call Why is this problem happening ? Thx
2
0
489
Jun ’21
Break Line
When I use: Text("My text \nhas a break line") The output is: My text has a break line PERFECT - I have "My text" and in the next line, I have "has a break line" However if I have: Text(mymodel.description) //where this is returning from an API call and mymodel.description contains "My text \nhas a break line") It doesn't work. The output is: My text \nhas a break line Why ?
1
0
1k
Jun ’21
Dismiss Modal with animation
I have a button on my modal and I want to dismiss the modal with animation. Right now it just closes it. HStack {             Spacer()             Image(systemName: "xmark")               .font(.system(size: 16, weight: .medium))               .foregroundColor(.white)               .frame(width: 36, height: 36)               .background(Color.black)               .clipShape(Circle())                               .onTapGesture {                 self.showModal.toggle() -- HERE               }                         } How can I do that ? Thx
0
0
440
Apr ’21
Render HTML
When rendering HTML into my view, I have the following part: struct HTMLStringView: UIViewRepresentable {   let htmlContent: String   func makeUIView(context: Context) - WKWebView {     return WKWebView()   }   func updateUIView(_ uiView: WKWebView, context: Context) {           let headerString = "headmeta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'/head"     uiView.loadHTMLString(headerString + htmlContent, baseURL: nil)   } } Everything works fine but some problems: If the html is long, It will create an another vertical scrollbar inside my view (so I will have 2 scrollbars) Font family and size still dont match the original view. How can I fix it ? Thx
0
0
472
Apr ’21
TabBar
In my SwiftUI app, I have a TabBar with 2 items: a) TabItem1 b) TabItem2 However on the View itself, I created 2 buttons: a) Button A b) Button B Now I need to switch TabBar items, using the buttons on the View. How can I do this ? ******* Button(action: { //call tabItem 1  }) {     Text("TabItem1") } Button(action: { //call tabItem 2  }) {     Text("TabItem2") } ***************************       TabView {       TabView1View()         .tabItem {           Text("TabItem1")         }               TabView2View()         .tabItem {           Text("TabItem2")         } Thank you
1
0
346
Apr ’21
Open Modal
I have a ForEach listing a lot of eventos, having 1 image button for each of them. When the button is clicked, I will open a modal with the selectedEvento. The problem is even though I've the line "self.selectedEvento = evento" inside of the button actions, when I click the button for the first time, the selectedEvento is being passed as nil. However if I click a second button, the process will happen succesfully. Code: ... @State var showModal = false @State var selectedEvento: Evento! ... ForEach(store.eventos) { evento in           VStack() {             Button(action: {               self.selectedEvento = evento               self.showModal.toggle()                             }) {             WebImage(url: evento.thumbnail)             }           }           .sheet(isPresented: $showModal) {             if self.selectedEvento != nil {               //open detailView             } else {               Text("Some Error State goes here")             }           }         } ** Why is this happening ? Shoudn't the first click also to be passing the selectedEvento ? Why it doesnt happen ? Thx
1
0
324
Apr ’21