Post

Replies

Boosts

Views

Activity

Run something before another thing
Hi, I have this code that I need to run in the exact line order, but I can't figure out how to do it. Things I have tried: DispatchQueue Aysnc completion handler functions Code: let pickedCat = Int.random(in: 1...4) //print("picked cat: \(pickedCat)") if pickedCat == 1 { getRandomJokes() randomJoke.text = "Random Joke: \(self.DadJokes)" //print("Random Joke: \(self.DadJokes)") }else if pickedCat == 2 { getAssistantJokes() randomJoke.text = "Random Joke: \(self.AssistantJokes)" //print("Random Joke: \(self.AssistantJokes)") }else if pickedCat == 3 { getKnockKnockJokes() randomJoke.text = "Random Joke: \(self.KnockKnockJokes)" //print("Random Joke: \(self.KnockKnockJokes)") }else if pickedCat == 4 { getRandomJokes() randomJoke.text = "Random Joke: \(self.RandomJokes)" //print("Random Joke: \(self.RandomJokes)") } if randomJoke.text == "Random Joke: " { randomJoke.text = "Random Joke: Failed to connect to server" }
39
0
2.6k
Apr ’21
Why is this crashing?
Whenever I run this code, after I have purchased something and it shifts up after leaving and reopening the page it crashes with the error "Index out of range". Code - https://developer.apple.com/forums/content/attachment/86665b01-4c50-47bd-a14d-ef95b58db511 Ideas? Thanks in advance! Ps: I can provide full project if needed.
17
0
1.8k
May ’21
Why is this clearing?
This is driving me crazy. I have this code: Utilities.getKnockKnockJokes {             self.previousKnockKnockJoke = self.currentKnockKnockJoke             print("currentKnockKnockJoke = \(self.currentKnockKnockJoke)")             self.currentKnockKnockJoke = KnockKnockJokes.knockKnockJokes.randomElement()!             print("newCurrentKnockKnockJoke = \(self.currentKnockKnockJoke)")             self.singleServeText.text = self.currentKnockKnockJoke         } The function that is called is bellow: getKnockKnockJokes Thank you in advanced!
3
0
549
Jul ’21
Change state from other struct
I have this code:     static var viewModels = [RestaurantListViewModel]() {         didSet {             dataSet = true             print("data set")         }     } When it didSet is called, I want it to change a state in another struct, how can I accomplish this?
2
0
752
Sep ’21
List Sections
I have this struct: struct Final_Restaurant_View: View {     var data: [RestaurantListViewModel]     @State private var isHome = false     var body: some View {         NavigationView{             VStack {                 List(data) {                     data in                         layout(data: data)                 }                 .listStyle(GroupedListStyle())                 Button(action: {                     isHome = true                 }, label: {                     Text("Go Home")                 })                 .padding()             }             .fullScreenCover(isPresented: $isHome, content: {                 ContentView()             })             .navigationBarTitle("Results")         }     } } Which is supposed to get data and display it in a list. The problem is that I can't find anything about sections on a table structured like this and therefore, it goes wack with the section title. Any Ideas???
5
0
1.6k
Sep ’21
Deeplinking
I have looked around and am confused about deep linking to a view that is not the default view, or passing information to that view which then impacts what is shown. Please help. Note: I am using the UIKit lifecycle
2
0
720
Sep ’21
Convert Key Pairs Array To Struct
I have a key pairs array: ["Id": XmGjU9gxS5s0CzP4S6-bHw, "Name": Pizzeria La Rocca, "Url": https://www.yelp.com/biz/pizzeria-la-rocca-seattle?adjust_creative=sxCnBn1t8D3B-4MLGRB_2g&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=sxCnBn1t8D3B-4MLGRB_2g, "Rating": 5, "Img": https://s3-media1.fl.yelpcdn.com/bphoto/kE6hbIfi4WdlIW52SF5KUw/o.jpg] How do I convert this to my struct? struct RestaurantListViewModel: Identifiable {     let name: String     let imageUrl: URL     let id: String     let rating: Double     let url: String //    let category: Array<String> } Thank you in advanced!
1
0
1.1k
Sep ’21