Post

Replies

Boosts

Views

Activity

Reply to Can't remove GitHub repository
Maybe you copied the other project to the same directory where the Zentastic project is? Therefore, you have two git repositories visible in the Xcode project? Just move the other project out of the same directory (using Finder), would that help? Can you find two .git directories starting from the root directory of your project? Then you have two repositories there and Xcode will show them. I'd start looking at this not from Xcode but from Finder and/or Terminal and fix things there.
Aug ’23
Reply to Timer running at increased speed each time I start it again
Sorry the delay, haven't stumbled on this discussion for a while. I am not quite sure if you need to restructure everything to make this work. But I have found out that having a model object (as in Model-View-Controller or Model-View-ViewModel architecture) is usually a good way to structure SwiftUI apps. The view simply displays things from the Model object and provides the user a way to manipulate the data (buttons, gestures, etc.). The model object contains the data and provides functions to manipulate it that the views call. Model is an ObservableObject having @Published properties. When those properties change, views are recreated with the new data values. This is what I was suggesting. Every time the timer fires in the Model object, it changes the value(s) of a/some @Published properties, causing the views to be updated. I have a demo app visualising some sorting algorithms that uses a timer. Basically shows what I described above, but is unfortunately a bit complex for your needs. Anyways, take a look if you still need to. The class SortCoordinator is here the Model, coordinating the visualisation of sorting algorithms, using a timer. As the timer fires, a step in sorting is done, changing positions of items in an array. The array is a @Published property, so the view updates when two numbers in the array change places while the sorting is advancing. The ContentView just shows the data from the SortCoordinator, view being updated whenever the @Published properties change. Search for "timer" in SortCoordinator to see how it is used there and how it updates the properties.
Jul ’23
Reply to Timer running at increased speed each time I start it again
I would restructure this so that the views observe a timer, which is an ObservableObject. From one of my (older) apps you may not want to directly follow: class CountDownClock: ObservableObject { @Published var ticksLeft: Double = Constants.startTickCount @Published var alertNow: Bool = false private var targetDate: Date = Date(timeInterval: Double(Constants.startTickCount)/Double(Constants.ticsPerSecond), since: Date()) private var alarmSound: AVAudioPlayer? private var timer: Timer? private var counterTick: Int = 0 ... public func start(withReset reset: Bool) { ... CountDownClock would have the start, stop, reset etc functions called from view controls. For example, below the ContentView has a tap gesture defined and when the user taps the subview, the timer is either started or reset. The views then just update their state when the timer ticks since the clock is an ObservedObject: struct ContentView: View { @ObservedObject var clock: CountDownClock var pauseTap : some Gesture { TapGesture(count: 1) .onEnded { _ in if self.clock.isTicking() { self.clock.stop() } else { self.clock.start(withReset: false) } } } ... var body: some View { ... VStack { ... Text(self.clock.description) .gesture(self.pauseTap) } .gesture(self.resetTap) ... By the way, Bool already has a .toggle() so you do not have to implement your own toggleStart().
Jun ’23
Reply to Coding help requested
Just remembered I've done something similar before. Here's the code: if let soundURL = Bundle.main.url(forResource: soundFile, withExtension: "m4a") { do { if debug { print("Playing now.") } alarmSound = try AVAudioPlayer(contentsOf: soundURL) if let player = alarmSound { player.prepareToPlay() player.play() } else { if debug { print("Could not load alarm sound file!") } } } catch { if debug { print(error.localizedDescription) } } } In general, I would also add print statements (or logging using Logger) to all the places things went the wrong way. That way you can more easily identify what is the actual issue.
Jun ’23
Reply to Coding help requested
Found your GitHub repo, unfortunately it did not contain the Xcode project file so couldn't get it up and running. I would change this: guard let url = Bundle.main.url(forResource: chimesSoundEffect, withExtension: "mp3") else { return } to this: guard let url = Bundle.main.url(forResource: chimesSoundEffect, withExtension: "mp3") else { print("No sound file found") return } To see if the file is actually found. Furthermore, I would change this: let chimesSoundEffect = "Chimes-sound-effect.mp3" to this: let chimesSoundEffect = "Chimes-sound-effect" Since you already have the withExtension in the Bundle.url call. Also I would check if you have included the mp3 file in the Target membership of the app: 1. First in Xcode, select the mp3 file in the left hand side where the project files are. 2. Check from the Inspector (View > Inspectors > File) and then see from the Target Membership section if there is a check in the checkbox for the app target. If not, the mp3 file is not included in the target binary and cannot be found.
Jun ’23