Post

Replies

Boosts

Views

Activity

Show JSON output to screen?
How would I take the output from JSON and print it to the IBOutlet's newsview? Thanks! class ViewController: UIViewController {   @IBOutlet var newsview: UITextView!   override func viewDidLoad() {     super.viewDidLoad()     // Do any additional setup after loading the view.     // API Endpoint:   let urlString = "[string withheld]"   let url = URL(string: urlString)   guard url != nil else {     debugPrint("URL IS nil")     return   }   let session = URLSession.shared   let dataTask = session.dataTask(with: url!) { (data, response, error) in     if error == nil && data != nil {       let decoder = JSONDecoder()       do {         let newsFeed = try decoder.decode(NewsFeed.self, from: data!)         print("Result: \(newsFeed)")       //  newsview.text = NewsFeed as? String!       } catch {         debugPrint("Error in JSON Parsing!")     }   } }   dataTask.resume() }   override func viewDidAppear(_ animated: Bool) { }
6
0
907
Jul ’21
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
601
Apr ’21
Updated code for Sharesheet in iOS 15?
I'm trying to display a share sheet and am using examples from the Internet but am getting the following warning: "'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead" Here's the code I'm trying to use: func shareButton() {   let url = URL(string: introText)   let av = UIActivityViewController(activityItems: [url!], applicationActivities: nil)  UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil) } Thanks, Dan Uff
5
0
3.1k
Dec ’21
*** BEWARE OF XCODE 13.3 (13E113) ***
Hi, I am writing this to WARN other developers about a problem that I have run into with Xcode 13.3 (13e113). Ever since downloading this version, I have noticed that my apps have bloated in size. From 23mb to 55mb and above. After an investigation, I noticed that Xcode was duplicating project and other files. Such as [nameofproject] [nameofproject2], etc. Because of this, not only did my project get bloated, but when I try to delete some of the duplicate files (yes, I know what to delete and what NOT too) this would then allow Xcode to delete even MORE FILES each time I went into the project. There is nothing worse then going into a project that you've worked MONTHS on and seeing RED FILES inside the project (red files means not there). So, I keep backups of all my apps. Restoring these backups cause the same problems. This is a notice to all developers -> CHECK YOUR PROJECT FILES FROM THE FINDER so you don't experience this problem. I would HOPE someone from Apple will see AND READ this and maybe even CONTACT ME so I can make DAMN sure this never happens again. Thank you, Dan Uff
4
0
1.6k
Mar ’22
SwiftData: Unable to delete (Xcode 16)
I am using Xcode 16 and am doing a future app with SwiftData. I have the data in a List. When I try to delete a row, it deletes and seems to save the deletion. But when I list the data again, what I deleted comes back. Here's the code: { for index in indexSet { let chat = chatLog[index] modelContext.delete(chat) // do { // try modelContext.save() // // } catch { // // print("Error saving: \(error)") // // } } } CHAT: Is a variable to hold the data. CHATLOG: The variable in the List. Thank you. Dan Uff
4
2
1k
Jun ’24
FYI: Xcode and Disk Space
I discovered a disk space issue with Xcode on my 1TB hard disk. Xcode doesn’t delete old or unused Simulators, causing them to mix and consume valuable space. Deleting them from the Window > Devices & Simulators menu didn’t work, so I used Disk Utility to find and delete them. However, they persisted. To regain disk space, I completely removed Xcode and the Developer Folder. After reinstalling Xcode, I regained about 80% of my disk space. Despite unmounting the Simulators, they remained. For those unable or unwilling to do this, the Mac App Store offers DevCleaner, a utility that removes old Xcode Cache and Simulators. Thanks. I hope I've helped someone else. Dan Uff
3
0
519
Feb ’25
Xcode 26 Beta Rebooting Problems
Hi, I've been running Xcode 26 beta ever since Beta 1 and haven't had rebooting problems. Now with Xcode beta (Version 26.0 beta 4 (17A5285i)) I'll be working on a project when the system (Mac mini 2025) suddenly reboots itself. This has been going on since beta 3. I am also running MacOS 26.0 Beta (25A5316i). I have filed a bug report. Is anyone else having this problem? Thanks, Dan Uff
3
3
196
Jul ’25
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.9k
May ’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.9k
Feb ’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
534
Mar ’21
Apple Watch App not Displaying Back "<" Button
Hi, I'm currently developing an Apple Watch app with Swift and Storyboards. The main screen consists of three buttons going to three different view controllers. When I go to one view controller, it doesn't display the normal back "" button at the top-left corner, even though it works. I tried this with an older project, with a similar setup and it works as it should. I have no code to show because it works like it should. It seems to be with the storyboard. Anyone else have this problem? Thanks, Dan Uff The code is exactly the same in both projects, with
2
0
1.2k
May ’21
iOS 16, AVFoundation, Text-to-Speech
Hi, I've been having problems with the AVFoundation and getting text to speech to work with iOS 16. I have a button which activates the text to speech that says the time. It worked with iOS 15 but not 16. Anyone else having a problem? Here's the code: (Note: dtd is coming from another Swift file). import Foundation import AVFoundation struct SUINightMode: View {      @ObservedObject var dtd = DateTimeData()      @Environment(\.presentationMode) var presentationMode      @State private var date = Date()        var body: some View {              ZStack {                  Color.black                    .ignoresSafeArea()                  GeometryReader { cen in                    VStack (alignment: .center) {                  Text("\(dtd.timeString(date: dtd.date))")             .foregroundColor(.green)           .font(.system(size: 120, weight: .bold, design: .rounded))           .alignmentGuide(VerticalAlignment.center, computeValue: { $0[.bottom] })                               .position(x: cen.size.width / 2, y: cen .size.height / 2)           HStack(alignment: .center) {           Text("\(dtd.dayString(date: dtd.date)), ")             .foregroundColor(.green)             .font(.system(size: 50, weight: .bold, design: .rounded))             Text("\(dtd.dateString(date: dtd.date))")             .foregroundColor(.green)           .font(.system(size: 50, weight: .bold, design: .rounded))     }     }       Image(systemName: "speaker.wave.3.fill")           .resizable()           .foregroundColor(.green)           .frame(width: 50, height: 30)           .padding(10)           .position(x: 120, y: 40)           .onTapGesture {             let synthesizer = AVSpeechSynthesizer()             let speakTime = AVSpeechUtterance(string: "The time is, \(dtd.timeString(date: dtd.date))...., today is \(dtd.dayString(date: dtd.date)) \(dtd.dateString(date: dtd.date))")             synthesizer.speak(speakTime)           }       Image(systemName: "arrow.left")           .resizable()           .foregroundColor(.green)           .frame(width: 45, height: 30)           .position(x: 40, y: 40)       .onTapGesture {         presentationMode.wrappedValue.dismiss()       }       .onAppear(perform: {let _ = self.dtd.updateTimer})       }     }       } } struct SUINightMode_Previews: PreviewProvider {     static var previews: some View {       if #available(iOS 15.0, *) {         SUINightMode()           .previewInterfaceOrientation(.landscapeRight)       } else {         // Fallback on earlier versions       }     } }
2
0
1.3k
Nov ’22