The problem has returned - again.
Post
Replies
Boosts
Views
Activity
I received an update a couple of hours ago and the problem has now fixed itself.
If anyone would like to know a likely reason for this, please read through the thread at Swift.org Forum. Test code included.
3 days ago I said I didn't wish to sound critical. Ha!. I'd been hoping someone from Apple would come forward, even if they were to say I've been wasting my time. As we all know, they're extremely reluctant to own up when something doesn't work. SwiftUI is promoted to be cross-platform across Apple platforms - including macOS. They don't tell us this only applies for apps the size of an iPhone.
I think I have every right to be critical, and I would very much appreciate a response from Apple - hopefully with some hope that I won't need to abandon this project.
OK, so it was a dumb question as I now know it's possible to use VStack, HStack, etc. However, the recent macOS / Xcode update (15th March 2022) has introduced warning messages:
Expression requiring global actor 'MainActor' cannot appear in default-value expression of property '_callsign'; this is an error in Swift 6
With no clues on how to solve. If only Apple would spend a little more time writing user friendly documentation.
If Apple knew how to write documentation and provide examples, I wouldn't have to ask on this useless forum.
To be clear, the above code produces this:
The app I'm working on looks like this:
The spectrum view is updated every 333ms from a source I have no control. The 40 Text fields and 73 Buttons are updated from a local server every 500ms. The app takes 12 seconds to launch and clicking the read close icon causes the app to hang for 20 seconds. While the networks are connected it's impossible to Quit, because the main thread is running at 99% cpu. I'm hoping SwiftUi can do better than this.
As an experiment, I tested the spectrum view in a standalone app. I consumed only 1% of cpu.
This is pathetic. I can't find a single way to render markdown on the Mac. Not even a Safari extension or in TextEdit. There are plenty of editors on the App Store that can do it, but not what I want.
Apple is promoting Swift Package Manager, so there really is no excuse.
Apple can't remove the App Store version, so perhaps the backend is broken and they don't have a backup. But it would nice if they would come clean and tell us what the **** is going on. Their refusal to own up and communicate is quite normal, so good luck to those waiting for approval.
Is it viable to use Microsoft's Visual Studio instead of relying on Xcode?
Having experimented with every conceivable variation of this very simple app, I can only conclude the problem is within Apple's Swift Compiler. It's a compiler bug they don't tell us about. I suspected every app in the App Store is also eating memory without releasing it. Nobody cares or even notices, because the idiots who have the iPhone glued to their hands only use these app for a short time. Try developing a real app for macOS with lots of buttons and this issue becomes very serious.
So I've answered my own question.
I'm currently developing on Big Sur. Can anyone tell me if Apple have fixed this in any of the latest beta versions?
To and Dirk-FU. I was wrong to say memory leaks. The issue is memory heap or allocation, or both. The Timer thing is interesting, but it make no noticeable difference.
I added a an init() with a print statement to ViewModel and ContentView. They only instantiate once.
I've also tried compiling a release version. According to Activity monitor, this has a smaller footprint to begin with, but slowly grows, and by even more as the button is pressed.
The thing is, this is a little test app to try and figure out what's going on in my real app. My real app has over 40 Buttons, 8 Pickers with dynamic arrays, and a graphical 'spectrum scope' with a graticule and a filled polygon shape. All interacting with 2 network sources in real time. This does have memory leaks and heap allocation issues - at about 100kB per second.
I've been experimenting where each class is instantiated - without any success so far.
As you can tell, I'm a novice. It would help if Apple's documentation told me what's going on. For example, they say the UI runs on the main thread, but they don't say if that applies in a Button closure. In Activity Monitor I can see more threads than I would have expected.
This is the most ridiculous solution I've ever come up with, but it works.
Spacer().onchange - really?
Please could someone from Apple, or anyone, show me a more elegant way.
HStack {
Text("Symbol Rate")
Spacer().onChange(of: vm.response.RxSymbolRate, perform: { value in
symbolRateSTATE = vm.response.RxSymbolRate
})
Picker("", selection: $symbolRateSTATE) {
ForEach(vm.response.RxSymbolRateArray, id: \.self) {
Text($0)
}
}
.onChange(of: symbolRateSTATE, perform: { newState in
vm.request(action: .RXSR, param: newState)
})
.onChange(of: vm.response.RxSymbolRate, perform: { newState in
symbolRateSTATE = newState
})
}
Can you show enough code to reproduce the issue? I guess your ViewModel is sort of broken.
I'd love to know what parts you guessed, because I've wondering about the ViewModel too. In fact, I've always been confused on where things need to initialised. Logic tell me the the ViewModel (source of truth) should be first, but that's impossible these days. I have...
@main
struct Sat_ControllerApp: App {
@StateObject var vm = ViewModel()
var body: some Scene {
WindowGroup {
ContentView().environmentObject(vm)
}
}
}
and in ViewModel...
final class ViewModel: ObservableObject, ActiveDelegate {
@Published var response = ServerStatusAPI()
The ActiveDelegate protocol is used in a NetworkService class.
I should also mention UI has hundreds of memory leaks. Perhaps I should be using Combine, if only I could understand it.
Thank you for your help.
This is my SwiftUI interface - that's about to be junked.