Post

Replies

Boosts

Views

Activity

Reply to College Documents for the Challenge
I think it is explained here, with many other details: https://developer.apple.com/wwdc21/swift-student-challenge/ Provide school information. Upload your most recent class schedule or other most recent proof of enrollment (PDF, PNG, or JPG) and the contact information for your educational supervisor. Documentation is accepted in all languages. Good luck. And if that answers your question, don't forget to close the thread.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Math Problem, entering an answer
When you post code, you should use Paste and Match Style to avoid all the extra lines that make reading difficult. Your problem seems to be here: @IBAction func btncheckAnswer(_ sender: Any) { if (ranA) + (ranB) == answer { correctAnswer() } else { wrongAnswer() } } Where do you get answer ? With this code it is always 0 Line 34 should probably be the other way: answer = Int(youAnswer.text) ?? 0 Note: no need to enclose randA and randB in parentheses. Reformatted code: import AVFoundation import Foundation class YouSolveIt: UIViewController { @IBOutlet var topProblem: UILabel! @IBOutlet var botProblem: UILabel! @IBOutlet var youAnswer: UITextField! @IBOutlet var actualCard: UIImageView! let speakit = AVSpeechSynthesizer() var problem1 = Int(0) var problem2 = Int(0) var answer = 0 var ranA = 0 var ranB = 0 override func viewDidLoad() { super.viewDidLoad() // Load Flash Card image: actualCard.image = UIImage(named: "FlashCard") solveitproblem() } func solveitproblem() { let ranA = Int(arc4random_uniform(UInt32(9))) let ranB = Int(arc4random_uniform(UInt32(9))) topProblem.text = String(ranA) botProblem.text = String(ranB) youAnswer.text = String(answer) let speakProblem = AVSpeechUtterance(string: "What is \(topProblem.text! + ", plus ," + botProblem.text!)") speakit.speak(speakProblem) } @IBAction func btncheckAnswer(_ sender: Any) { if (ranA) + (ranB) == answer { correctAnswer() } else { wrongAnswer() } } func correctAnswer() { let right = [1,2,3,4,5] let randomIndex = Int(arc4random_uniform(UInt32(right.count))) switch(randomIndex) { case 1: let speakRight = AVSpeechUtterance(string: "That is correct") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() case 2: let speakRight = AVSpeechUtterance(string: "You're right!") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() case 3: let speakRight = AVSpeechUtterance(string: "Correct! Let's try.") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() case 4: let speakRight = AVSpeechUtterance(string: "You are right! Next Try.") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() case 5: let speakRight = AVSpeechUtterance(string: "Great answer!") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() default: let speakRight = AVSpeechUtterance(string: "Very good!") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() } } func wrongAnswer() { let wrong = [1,2,3,4,5] let randomIndex = Int(arc4random_uniform(UInt32(wrong.count))) switch(randomIndex) { case 1: let speakRight = AVSpeechUtterance(string: "That is wrong") speakit.speak(speakRight) case 2: let speakRight = AVSpeechUtterance(string: "You're wrong, please try again.") speakit.speak(speakRight) case 3: let speakRight = AVSpeechUtterance(string: "No, that's not it. Please try again.") speakit.speak(speakRight) case 4: let speakRight = AVSpeechUtterance(string: "No") speakit.speak(speakRight) default: let speakRight = AVSpeechUtterance(string: "I'm sorry, no. Please try again.") speakit.speak(speakRight) } } }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Notification Center Help
@ ZoneX You say: Okay so your solution dismisses my HdVC but when it goes to FaVC it doesn't seem to have the data. I just see a white screen which means my transferred item is nil still. What is the data you try to transfer ? Which var content ? If it is currentFav, then I would : DispatchQueue.main.async { // pour update UI if let passDataVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FavViewID") as? FavouritesVC { passDataVC.currentFav = item // if this is what you want to pass self.present(passDataVC, animated: true, completion: nil) } Please, when you answer and there are several posts, please remind who you are replying to.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Control the volume up and down button
AFAIK, it is forbidden to change the behaviour of those buttons. They are reserved for sound volume. It would be very misleading for user to have the buttons not reacting as they should. Of course you could detect volume change and use the volume information for your purpose, but you would be limited to the min and max volume values. So, as a conclusion, don't try to do that. May read discussion in this old thread: https://developer.apple.com/forums/thread/107241
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Notification Center Help
I miss something in the logic. The notification is sent by FavoritesVC. But where is currentFav initialised ? And why don't you simply append in HockeyDetailVC ? In your IBAction @IBAction func addToFav(_ sender: Any) { let alert = UIAlertController(title: "Favourite Added 💙", message: "\(name.text ?? "") is added to favourites", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil)) self.present(alert, animated: true, completion: nil) print("Favourite button Pressed") let passDataVC = FavouritesVC() /* I think passDataVC is supposed to be different because I use storyboard but I don't know what else it's supposed to be. */ self.present(passDataVC, animated: true, completion:nil) } Line 5 and next will be executed before you tap OK. Is it what you want ? In addition, you will probably have an error like: 2021-03-31 15:20:44.949122+0200 simpleTest[54293:11989110] [Presentation] Attempt to present xxxx.FavouritesVC: 0x7fbfd14534c0 on xxxx.HockeyDetailVC: 0x7fbfd3014000 (from xxxx.HockeyDetailVC: 0x7fbfd3014000) which is already presenting UIAlertController: 0x7fbfd1877a00. I changed as follows to make it work (call the next VC in the completion of button). FavViewID is the ID of FavouritesVC @IBAction func addToFav(_ sender: UIButton) {      let alert = UIAlertController(title: "Favourite Added 💙", message: "\(name.text ?? "") is added to favourites", preferredStyle: .alert) alert.addAction(UIAlertAction( title: "OK", style: UIAlertAction.Style.default, handler: { _ in DispatchQueue.main.async { // pour update UI if let passDataVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FavViewID") as? FavouritesVC { self.present(passDataVC, animated: true, completion: nil) } } })) self.present(alert, animated: true, completion: { print("Favourite button Pressed") } ) }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Dynamic List
There should be a button for the user to ask to add a card. This would append a card to an array of cards And the List uses this array as data source for display. See more details (replace students by your flashCards array. https://stackoverflow.com/questions/56654877/how-to-show-list-of-views-from-a-datasource-like-uitableview-in-swiftui
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Math Problem, entering an answer
Could you print values of ranA, ranB and answer ? Please report and tell what you entered in the textField @IBAction func btncheckAnswer(_ sender: Any) { print("randomA", ranA, "randomB", ranB, "answer", answer, "text", youAnswer.text) if ranA + ranB == answer { correctAnswer() } else { wrongAnswer() } }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21