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
Setting UILabels to Firestore data
Hi, I would like to be able to take two fields of a firestorm document and then set two UILabels to those fields. Here is my code: import SafariServices import WebKit import Firebase class TheRiddle: UIViewController {          @IBOutlet weak var leading_TheRiddle: NSLayoutConstraint!     @IBOutlet weak var trailing_TheRiddle: NSLayoutConstraint!          @IBOutlet weak var CurrentRiddle: UILabel!     @IBOutlet weak var PreviousRiddle: UILabel!          var menuOut = false          override func viewDidLoad() {         super.viewDidLoad()                  let db = Firestore.firestore()                  db.collection("TheRiddle").document("Riddles").getDocument { (document, error) in                          //check for error             if error == nil {                 //check if document exists                 if document != nil {                 }else {                     if let currentRiddle = document!.get("CurrentRiddle") as? String {                         self.CurrentRiddle.text = "This Weeks Riddle: " + currentRiddle                     }                     if let previousRiddle = document!.get("CurrentRiddle") as? String {                         self.CurrentRiddle.text = "Previous Riddle: " + previousRiddle                     }                 }             }                      }                       }               @IBAction func RiddleAnswerForm(_ sender: Any) {         let vc = SFSafariViewController(url: URL(string: "https://forms.office.com/Pages/ResponsePage.aspx?id=ytAqTDte6UK-KD5v_kOm4Y843IzqmYtFlDtLrfRYsi1UMFpUMk1GN01GS05BVFlJUElONk4yR1hKUCQlQCN0PWcu")!)                  present(vc, animated: true)     }          @IBAction func menuTappedTheRiddle(_ sender: Any) {                  if menuOut == false {             leading_TheRiddle.constant = 150             trailing_TheRiddle.constant = -150             menuOut = true         }         else {             leading_TheRiddle.constant = 0             trailing_TheRiddle.constant = 0             menuOut = false         }         UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {             self.view.layoutIfNeeded()         }) { (animationComplete) in             print("The animation is complete")         } } } Thanks in advance!
12
0
1k
Feb ’21
Pushed over tabs
Hi, I am making an app and I am using tab navigation controller and the navigation controller, and whenever I push into another view controller through a segue, if I go to a different tab, then back to that one it's still on the pushed to view controller. Ideas on how to fix this. Thanks in advance!
11
0
943
Mar ’21
In App Settings
Hi, Something weird is going on with my code. I want it so when someone allows me to send notifications, if they go into my setting view controller to see that toggled on. Here is a link to my project: https://www.icloud.com/iclouddrive/0PDX_ZK3kyamqHjV8-hlDhZbw#Riddle_Wednesday Thanks in advance!
9
0
1.2k
Apr ’21
Why is this returning nil
Hi, this code is returning nil always. So frustrating! let today = Date() let calendar = Calendar(identifier: .gregorian) let components = calendar.dateComponents([.weekday], from: today) let nineThirtyToday = Calendar.current.date( bySettingHour: 90, minute: 30, second: 0, of: today) print(nineThirtyToday as Any) if components.weekday == 4 { if today = nineThirtyToday! { if UDM.shared.widgetDefaults?.value(forKey: "currentRiddle") as! String == currentRiddleFinal { currentRiddleFinal = "Waiting for update from server" } }else { print("Not Nine Thirty") } } UDM.shared.widgetDefaults?.setValue(currentRiddleFinal, forKey: "currentRiddle") print("Current Riddle: \(currentRiddleFinal)") } Thanks in advance!
9
0
1.6k
Mar ’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
I am getting this error message
I am an aspiring developer and would like some help with this issue, that is super annoying. Any Idea why I am getting this message? Thread 1: "[<UIViewController 0x7ff3bdc08a80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key leadingHome." I have tried: Deleting home and re-adding it reconnecting all the points on the home controller Deleting the class and re-adding it Making a new class and changing Home over to it Setting the constraints and menu button itself to the class You can download my project at: https://www.icloud.com/iclouddrive/0vC-WfbeKKjLa6V05ofqhyayw#Riddle_Wednesday Thanks so much in advance!
4
0
619
Jan ’21
Lost Connection
I have an M1 Mac and I am on Monterey beta 4. I have Xcode 12 and whenever I try to run my iOS app on my Mac natively, I get this error message. Could not attach to pid : “4837” Lost Connection Full Log Any Ideas? Thanks in advanced
4
0
1.7k
Nov ’21