Post

Replies

Boosts

Views

Activity

Reply to Array Only Shows Populated After Second Run Through
The gotoplaces() function is what utilizes the arrays: Thanks for showing the code. Then you need to call gotoaces() or (gotoplaces() or gotoPlaces()?) inside the completion handler. I thought that since the function was called after task.resume() meant that it finished? It is a very common misunderstanding among who are not accustomed to async call. task.resume() just triggers to start the task. When the task is finished, iOS tell your app that the task is completed. Another too simplified advice: Do not write any lines after task.resume().
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Array Only Shows Populated After Second Run Through
Have I somehow cleared the arrays without knowing? NO. You are using Arrays before they are populated. dataTask is an asynchronous call. The completion handler (line 25 { ... line 82 }) is executed after the task is complete. That printNames() on line 84 is executed before the task is completed. How to fix may depend on how you want to use the Arrays. Again, you are not showing the code using the Arrays.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Store Location from API into Array
When the print statement is within the do brackets, it shows it is filled, but once its after the task.resume(), it will only show a populated array after the second execution  You may be handling asynchronous method in a bad way. Which may caused by your hidden parts of code and that is another issue. You should better start a new thread which includes all relevant parts. Please do not ask things which is not included in the opening post. Keep one thread for one topic.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Store Location from API into Array
This is the entire printed console when the code is ran:  Thanks for showing the output, but the JSON, outermost structure is JSON object must start with { (opening brace). Seems a few lines are missing. Can you show really entire output? (UPDATE) Can you show really entire output? Sorry, but no thank you. Seems your Console Out contains outputs of two runs. The first 936 lines for the first run -- partial, and the latter for the second run -- entire. Found what's wrong -- there's no entry of type String for the key "location" in the response. Need some time to write a more detailed answer...
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Store Location from API into Array
The print statement on line 21 prints out the google api page There's no print statement on line 21 of my code, is it line 11? And you mean the URL string by the google api page? It would be far better copying all the outputs in the debug console than trying to describe them by words. then nothing else is printed until line 51, "value for location not found or not string". It is strange and would never happen. If line 51 would be executed, line 30 print(String(data: data, encoding: .utf8) ?? "?") is definitely executed.  I did try change the array type to double but same output.  Please show your code when talking about changing code. I really do not understand what you have tried. When I switch, on line 46, the key value to "name" it is still able to store the values of name into the array and prints out properly. I do not understand what you mean. What is switch? What is able to store the values? Please show actual code you used and actual output you saw. I've been picking parts from different forums to try and make this app. Seems you have chosen a very bad one. If you find NS-something in a code, you should better avoid it. (A little bit too simplified, but would be useful in many cases -- avoid NS-things.)
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Suggestion for a Quote of the Day App
I am wanting to call the fetch quote function every 24 hours. What code technique would you suggest? No technique, a simple strategy. On your app starting up (including getting foreground), call the API and get the latest While your app is running in the foreground, use timer and check the next update time every minute While your app is in the background or not running, do nothing. Users cannot see background apps
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Question: Swiftui http request without button
not working Sorry, but not working is the worst phrase to tell what is happening. Please try to tell what's happening precisely instead of just saying not working. I cannot get any clue with only seeing the two words. And you are missing one thing: Also, you need to remove mutating from doHttpRequest().
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Question: Swiftui http request without button
the app starts fine but as far as the for- loop starts, there is this issue: Seems we need to go deeper into the code which you have not shown in the opening post. Generally, you should not add one more questions which is not included in the first post. You asked Swiftui http request without button, and the issue is answered. Please try changing the ForEach as follows: &#9;&#9;ForEach(0 ..< dateien.count, id: \.self) { If you have something more, you should finish this thread and start a new thread for the new topic.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21