Post

Replies

Boosts

Views

Activity

Math Problem, entering an answer
Okay, I give up. I am making a Flash card game where the app will randomize two numbers, then the user would enter the answer. The app will then tell the user if he/she is correct. But I cannot seem to figure out how to get it to add two numbers and check if the user's correct or not. Any help is greatly appreciated! Here's the code: import UIKit 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)   } } }
5
0
587
Apr ’21
Looking for opinions - Math Tables in a List
Hi, I am looking for opinions on the best way to handle a problem I'm having. My client wants his app to show a list of math tables, such as 1+1 = 2, 2+2 = 4, and so on. I have a list view with said tables in an array, which I manually have to input in. He wants the list to go from 1 to 20. I'd assume that I would need some sort of for....next loop, but how would I show that in a list? Thanks for any help you can give. This is what I have so far: import SwiftUI import UIKit struct ATables: View {      var tables = ["Temporary","1 + 1 = 2","2 + 2 = 4"]        var body: some View {                NavigationView {               List {                  ForEach(self.tables, id: \.self) { show in                      HStack {           Image(systemName: "arrow.right")             .resizable()             .frame(width: 30, height: 20, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)           Text(show)             .font(.custom("Chalkboard", size: 50))           }         }       }.navigationBarTitle(Text("Addition Tables (1 - 20)"))           .navigationBarTitleDisplayMode(.inline)     } } struct ATables_Previews: PreviewProvider {     static var previews: some View {         ATables()     } } }
2
0
516
Mar ’21
Toolbar button not showing in Canvas
Hi, I have a toolbar and a share button on the left side. The button isn't showing up on the canvas, but does show when the app is run in the simulator or a device. Is this normal behavior or a bug? This is a test button so please forgive the print statement. Here's the code:         {           ToolbarItem(placement: .bottomBar)           {             Button(action: {               print ("Button Pressed!")             }               ){                              Image(systemName: "square.and.arrow.up")             }             }         }
2
0
1.8k
Feb ’21
Showing JSON contents to iOS screen output?
Hi, I have a json file that I have it printing to the terminal, but now I want to have the output go to an iPhone, iPad, and Apple Watch screen. Here's what I have in the viewDidLoad section.... override func viewDidLoad() {     super.viewDidLoad()          let data = GetData().$userData    print(data)          // Immediately get a quote upon app entry.     //getQuote()   } The $userdata and data are defined in another file. Again, everything parses fine in the terminal. If you need the other part of the code, please let me know. Thanks, Dan Uff
5
0
2.2k
Sep ’20
Showing new date on Widget at Midnight
Hi, I am in the process of developing an add-on widget for one of my apps that must show a new date at midnight local time. I've tried using the default widget code, and changing the line to:             let entry = SimpleEntry(date: entryDate)             entries.append(entry) Could someone give me a "hint" on what to do? Thanks, Dan
3
0
968
Jul ’20
Using WebKit Delegates
Hi,How would I go about using the standard WebKit delegates in SwiftUI, such as:func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) { activityView?.startAnimating() self.title = "Loading...." }Here's what I have so far:import SwiftUI import UIKit import Foundation import WebKit struct Support: View { var body: some View { NavigationView { VStack { WebView(request: URLRequest(url: URL(string: "https://www.connectingpeoplesoftware.com/iossupport")!)) }.navigationBarTitle(Text("Support")) } } struct WebView: UIViewRepresentable { let request: URLRequest func makeUIView(context: Context) -> WKWebView { return WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { uiView.load(request) } } struct Support_Previews: PreviewProvider { static var previews: some View { Support() } } }Thanks in advance,Dan
3
0
6.8k
Dec ’19