Post

Replies

Boosts

Views

Activity

Launch Screen Image
I have set in my info.plist file, the background and image I want for my launch screen. The image is 200px x 200px and for some reason, when the launch screen happens, the image gets stretched, not keeping the original size. How can I fix it ? Thank you
4
0
1.6k
Sep ’21
Picker without NavigationView
I have a picker on my view but it's not selectable unless I replace my VStack for a NavigationView. However I cant have a NavigationView on this page, otherwise it brakes other parts. What's the solution for that ? Thx VStack { Picker }
4
0
1.9k
Dec ’21
Nil
I have a view which goes to my Store, gets data from an API and bringing back to the view. var productId = 123 @ObservedObject var productStore = ProductStore()       init() {     productStore.getById(productId: self.productid)   } The object from ProductStore is coming back but when I try to use it: Text(self.productStore.product!.title) I get: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value Why this is happening if the object doesnt have nil values ?
3
0
540
Aug ’21
Showing Decimal value
I am trying to present a decimal variable containing the value of 66.67. So I am trying to do: Text("\(myVariable, specifier: "%.2f")") //Instance method 'appendinterpolation(_:specifier) requires that Decimal conform to _formtSpecifiable Text("\(myVariable, specifier: "%.2f")" as String) //I receive extra argument specifier in call How can I fix it ? Thx
3
0
891
Sep ’21
NavigationLInk
I have an array with 10 different categories. So I create NavigationLink for each of them, calling MyListView and passing data about the category. NavigationView { List(categories) { category in NavigationLink(destination:           MyListView(category: category) )             {           CategoryRow(category: category)   } } } So when I click in one of these 10 categories, I will call MyListView. Inside MyListView I have a call to the API bringing a lot of information about the chosen category. The problem here is, even before clicking in any category, MyListView is being called and the API is called for all the 10 categories. I only want to call MyListView and the API inside it, after selecting the category. Whats the problem here ? Thx
3
0
628
Sep ’21
Call 2o API after finishing 1st one
I have a button that when pressed should call an API which return an ID. Then having this ID, I will call a 2nd API. Button(action: { var id = self.callApi1() self.callApi2(id) }) { Text("Start") } How can I call the Api2 JUST when the Api1 was finished and returned its value ? Thank you
3
0
533
Dec ’21
Convert HTML to Text
In my SwiftUI project, I am trying to convert HTML to Text. Text("h1Test/h1p Test/pbr/spanTest/spanulliitem1/liliitem2/li/ul")           .font(.body)           .frame(maxWidth: .infinity, alignment: .leading)           .padding(.bottom, 16)           Is there a way to make it happen ? Thank you
2
0
5.3k
Feb ’22
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
API Error
I have this API call in my application. For some reason, the response is coming back nil. If I try the right URL, a JSON will be returned and all the nodes filled out. So I'm trying to get the error inside the if let error = error { but even putting a breaking point in there, the code is never reached. What am I doing wrong ? Thanks func getProductById(productId: Int, completion: @escaping (ProductModel) -> ()) {     guard let url = URL(string: "https://mysite/api/products/82") 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       if let data = data {         print("data")      }      if let error = error {         print("error")      }       guard let data = data else { return }      do {         let product = try! JSONDecoder().decode(ProductModel.self, from: data)         DispatchQueue.main.async {           completion(product)         }       }      catch {         print(error)       }    }     .resume()
2
0
1.4k
Aug ’21
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
Identifiable ID
I have a JSON from my backend which returns: [ { productId : 1 name: productA }, { productid: 2 name: productB } } And on my SwiftUI project I have a model: struct ProductModel: Identifiable, Codable, Hashable { //var id = UUID() var productId = Int var name = String } In my View, when I do a foreach to present all the products coming from my JSON, I got a message saying my model needs to be Identifiable to be using the foreach. That was the reason I created the var id = UUID() on my model. Now I dont have the foreach error message, however, I get the error: Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "id", intValue: nil) Shouldn't it be ok since I am creating the ID on my model ? Thank you !
2
0
1.3k
Aug ’21
Published Vars
I have an ObservableObject class that can return 2 different @published vars (product or products), depending on the function I call. But when I define the published vars, I am having an error message "Missing argument for parameter 'from' in call". It just happens for the first published var. What's the mistake? Thx class ProductStore: ObservableObject {   @Published var product = ProductModel() //getting error here   @Published var products: [ProductModel] = []   func getProducts() {     ProductApi().getProducts() { (products) in       self.products.append(contentsOf: products)     }   }   func getProductById(productId: Int) {     ProductApi().getProductById(productId: productId) { (product) in       self.product = product     }  } }
2
0
712
Aug ’21
WebView
I am trying to parse some html inside my app. Not an entire html page, but just few blocks of html code. So I'm using Ink package for that. // FIRST I HAVE A WEBVIEW import SwiftUI import WebKitstruct WebView : UIViewRepresentable {   var html: String  func makeUIView(context: Context) -> WKWebView {     return WKWebView()   }  func updateUIView(_ webView: WKWebView, context: Context) {     webView.loadHTMLString(html, baseURL: nil)   }} // IN HERE I'M PARSING THE HTML AND ALSO ADDING SOME STYLING TO IT import Foundation import Ink class ParseContent: ObservableObject {   var markdown: String = ""   func parse() -> String {     let parser = MarkdownParser()     let html = parser.html(from: markdown)       let htmlStart = "<HTML><HEAD></HEAD><BODY style=\"padding: 140px; font-size: 120px; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Open Sans,Helvetica Neue,sans-serif\">"     let htmlEnd = "</BODY></HTML>"       return htmlStart + html + htmlEnd   } } // IN HERE I AM JUST USING MY PREVIOUSLY CREATED WEBVIEW WebView(html: myHtmlContent) .onAppear() {         htmlContent = ParseContent().parse()     } So here are my questions: Why the styling isn't working since I am concatenating the html ? I see it in a lot of tutorials but cant understand why not working. I would like to have the font inside my WebView, the same as I have for my other components like Text("abc") so I would keep a pattern and the visitor woudnt realize they are different components. How to set the WebView without a vertical scroll ? Keeping the entire height coming from the parsed html ? Thank you guys :)
2
0
1k
Jan ’23
DateFormatter - String to Date
struct MyView: View { var body: some View { //this value is coming from a JSON var myDate = "3000-01-01T08:00:00-08:00" //Here I'm calling my function formatDate, passing my myDate parameter: Text(formatDate(dateString: myDate)) } } func formatDate(dateString: String) -> Date { //first I dont know why my parameter gets here nil   let dateFormatter = ISO8601DateFormatter() //at the dateFormatter, doesnt matter the options I set, the return is always the same.   dateFormatter.formatOptions = [ .withFullDate,     .withFullTime,   ]   let finalDate = dateFormatter.date(from: dateString)!   return finalDate } I just need the get the date string, convert it to the format MM dd, yyyy - hh:mm How can I do it ? Thank you
2
0
665
Sep ’21
Calling a View
I have a button in MyViewA and after clicking on the button search, I want to call MyViewB, passing the variable search. How can I call a different view after clicking a button ? var search: String = "abc" Button(action: { MyViewB(keyword: self.search) }) { Text("Search") } Thank you
2
0
489
Sep ’21