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.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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().
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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
Reply to Get Wordpress posts
Maybe your blog is configured to provide only a snippet of the blog post in the feed? Have you checked that?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’23
Reply to Xcode source control unknown green file. How to remove?
If you do a commit, is that deleted file then committed as deleted from git?
Replies
Boosts
Views
Activity
Aug ’23
Reply to Sending invites to friend
Would CloudKit Share be something you could use?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’23
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.
Replies
Boosts
Views
Activity
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.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’23
Reply to Can we open Phone app from Widget??
Perhaps you could use either the widgetURL view modifier or the WidgetKit Dynamic Island widgetURL. You would need to know how to compose the URL for another app though.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’23
Reply to Thread 1: Fatal error: expected attribute to be Codable
Couldn't find a place where it says MoneySplitter conforms to Codable.
Replies
Boosts
Views
Activity
Jul ’23
Reply to Library not loaded: @rpath/FBLPromises.framework/FBLPromises
Lots of search results on this kind of issues in Stackoverflow and elsewhere. Have you tried out what they suggest?
Replies
Boosts
Views
Activity
Jun ’23
Reply to Use of 'print' refers to instance method rather than global function 'print(_:separator:terminator:)' in module 'Swift'
How do you call it? Do you have another print method in your own code?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to "Discover Observation in SwiftUI" session has a bug
Does it help to do var userName: String? = nil?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to Watch only app
What is the actual problem you are facing? I have created a watch only app in Xcode, tested it in simulator and my own watch, added the details in App Store, have distributed it for testing in TestFlight without issues.
Replies
Boosts
Views
Activity
Jun ’23
Reply to Expected an ISO 8601 date - App Store Connect API
Sometimes the fractions of a second cause problems in ISO8601 date strings. Could it be that? Have you checked how App Store Server API does it: https://github.com/apple/app-store-server-library-swift
Replies
Boosts
Views
Activity
Jun ’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().
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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.
Replies
Boosts
Views
Activity
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.
Replies
Boosts
Views
Activity
Jun ’23