Post

Replies

Boosts

Views

Created

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
567
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.8k
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
1.1k
Jun ’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
Apr ’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 ?
Replies
3
Boosts
0
Views
567
Activity
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()                }
Replies
1
Boosts
0
Views
1.8k
Activity
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 ?
Replies
1
Boosts
0
Views
1.1k
Activity
Jun ’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
Replies
2
Boosts
0
Views
5.3k
Activity
Apr ’21