Post

Replies

Boosts

Views

Activity

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
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
App Crash - Message error
When I run my app with my phone connected, suddenly the app crashes. I don't have any information on the console, but I have the following message error in the @main line. Thread 1: EXC_BAD_ACCESS (code=1, address=0x28) @main struct MyApp: App { How can I know what is the problem and where to check for message errors when the app crashes ? Thank you
0
0
335
Sep ’21
EXC_BAD_ACCESS
My app suddenly crashes exposing this message error: EXC_BAD_ACCESS (code=1, address=0x5c)  I tried to debug but can't find a solution. I believe using Instruments could be easier to find it. However Instruments has a lot of items. What would be the one responsible for debugging this kind of error I'm having ? Thank you
0
0
515
Sep ’21
TabBar and Views
I have a TabBar with 5 different views for each TabBar item. All these 5 views have long content wrapped in a ScrollView. So let's say I chose my 2nd TabBar item and scroll on this view. Then I move away to another view and when I hit the 2nd TabBar item again, I want this view scrolled to the top and not at the position I left on the first visualization. How can I do that? Thx
0
0
355
Nov ’21
TabBar Transitions
I have a TabBar with 3 items: Home ScrollView Products NavigationView Users NavigationView When clicking on the tabBar buttons, I will go back to the related view. However, at the point where I had left. I would like to every time I move to a different tab, it starts fresh like 1st time. a) If it's a scrollview, after coming back to the tab I would like the view scrolled to the top. b) If it's a navigationView, after coming back to the tab, I would like to scroll to the top and move to the Navigation root list. How can I do it. Thx folks
0
0
347
Dec ’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
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
345
Apr ’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
Http Request with Querystring Parameter
I am trying to call an API, but I need to pass the parameter via querystring. But somehow it's not working. Where is the mistake ? func getProductById(productId: String, completion: @escaping (Product) -> ()) {     guard let url = URL(string: "https://mysite.com/product/" + productId) else { return }                       var request = URLRequest(url: url)     request.httpMethod = "GET"     request.setValue("application/json; charset=UTF-8", forHTTPHeaderField: "Content-Type")             URLSession.shared.dataTask(with: request) { (data, request, error) in       guard let data = data else { return }                       do {         let product = try! JSONDecoder().decode(Product.self, from: data)         DispatchQueue.main.async {           completion(product)         }       }               catch {         //print(error)       }             }     .resume()                }
1
0
1.7k
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
Multiple environmentObject
Trying to understand API calls in SwiftUI, I got some doubt about environmentObject.Here, I have a file Network.swift which contains a method to get Users. So I create an environmentObject on my ProjectNameApp.swift file (see code).But this is my question: Let's say I have an another file Products.swift containing methods related to the products API. How I would set it in my ProjectNameApp.swift file ? // Network.swift import SwiftUIclass Network: ObservableObject {     @Published var users: [User] = []    func getUsers() {         guard let url = URL(string: "https://jsonplaceholder.typicode.com/users") else { fatalError("Missing URL") }        let urlRequest = URLRequest(url: url)        let dataTask = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in             if let error = error {                 print("Request error: ", error)                 return             }            guard let response = response as? HTTPURLResponse else { return }            if response.statusCode == 200 {                 guard let data = data else { return }                 DispatchQueue.main.async {                     do {                         let decodedUsers = try JSONDecoder().decode([User].self, from: data)                         self.users = decodedUsers                     } catch let error {                         print("Error decoding: ", error)                     }                 }             }         }        dataTask.resume()     } } // ProjectNameApp.swift@main struct ProjectNameApp: App {     var network = Network()    var body: some Scene {         WindowGroup {             ContentView()                 .environmentObject(network)         }     } } Would be the right implementation something like this ? For each API group a new environmentObject ? // ProjectNameApp.swift@main struct ProjectNameApp: App {     var network = Network()     var product = Product()    var body: some Scene {         WindowGroup {             ContentView()                 .environmentObject(network)                 .environmentObject(product)         }     } } Thank you
1
0
3.3k
Aug ’21
Text - Formatted HTML
I have an app where I am bringing some formatted text from the database. The problem is when I use: Text(myDataComingFromJson), of course, my text will be something like: I've created an extension where I can remove the HTML tags but then all my text will be in only one paragraph and the lists won't exist () The second approach would use WKWebView but then I will have some headaches formatting text or loading extra views to do the job. Question: Is there a way to use Text directly, but keeping break lines and lists? Even though I have to change the content at the database level ? I also have tried using \r\n in the database but still didn't work. Is there a better solution? Thank you all
1
1
456
Aug ’21
Calling API
The main view on my app brings data from 3 different API calls. So when the app starts, the data are still being returned, so nothing is seen but just a blank space. They are basically a Thumbnail and its title. What would be the best solution for that: Have a temporary thumb and a text like "loading" OR any other approach? Thank you
1
0
723
Sep ’21
App Crashing
My app works fine but depending on something (that I still don't know), the app suddenly crashes. The only message error I have is: Thread 1: EXC_BAD_ACCESS (code=1, address=0x5c) How can I debug it and know exactly why this is happening ? Thank you,
1
0
357
Sep ’21