SOLVED - with a sledge hammer! First, I copied all Xcode projects to an external disk and unmounted it, then I did a Command-R on reboot and ran First Aid on all 3 APFS partitions. No errors were reported.
On restart, I created a new Xcode project and "magic", I was able to add Package Dependencies once again! Perhaps it was because I'd been duplicating some of my folders contain projects - the novice way to create a branch - and that was confusing some of Xcode's undocumented and hard to find files.
The real odd thing is, Xcode is now creating an extra Tests folder for Previews (and probably other thing it didn't before). I really wish Apple would concentrate on getting CURRENT things working, including decent documentation and telling us how to create modern Help files (instead of the obsolete ones), before bringing out new Beta versions with even more bugs.
Post
Replies
Boosts
Views
Activity
Don't you buy a new machine with a fresh install for each minor update?
I need direction (or an example) for the 3 questions in the following snippet. Please can you help?
import Foundation
import NIO
import NIOFoundationCompat
class NetworkService {
var connected = false
// Q1 Are these declarations correct?
var group: MultiThreadedEventLoopGroup
var bootstrap: ClientBootstrap
var channel: Channel?
init() {
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
self.bootstrap = ClientBootstrap(group: group)
.channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1)
.channelInitializer { channel in
channel.pipeline.addHandler(ResponseHandler())
}
defer {
try! self.group.syncShutdownGracefully()
}
}
public func connect(host: String, port: Int, completion: (_ success:Bool, _ error:String) -> Void) {
if connected {
completion(false, "ERROR: already connected")
return
}
do {
// Q2 How to change to the correct thread - and return to main?
channel = try bootstrap.connect(host: host, port: port).wait()
} catch {
completion(false, "ERROR: NetworkService.connect() failed to connect")
connected = false
return
}
connected = true
completion(true, "")
}
public func disconnect(completion: (_ success:Bool, _ error:String) -> Void) {
if !connected {
completion(false, "ERROR: already disconnected")
return
}
do {
// Q3 How to change to the correct thread - and return to main?
try channel?.close().wait()
} catch {
completion(false, "ERROR: NetworkService.disconnect() failed to disconnect")
return
}
connected = false
completion(true, "")
}
//
// more follows...
//
Of course, any other suggestions will be most appreciated. Thank you.
Thank you for this Mathew. I very much appreciate your time.
I did go ahead and posted to the Swift forum. In fact, I've been receiving wonderful assistance from Cory Benfiled during the past few hours.
Here's the link to issue 50173 where I suggest anyone watching should divert their attention.
The workingdogintokyo solution does work. Unfortunately in my case, it would introduce too much bloatware that would be hard to maintain. There's little point in re-factoring only to then start adding loads of extra @Things all over the place So, I've decided to give up with those nice looking Toggles and just use plain old Buttons. They're not as elegant and they can't be customised as much as they can on iOS, but at least they work.
I have structs for various devices, but this is the one for the Power Supplies.
struct PowerSupplyControl: View {
@Binding var psu: PowerSupplyStatus
@EnvironmentObject var vm: ViewModel
var body: some View {
HStack {
Text(psu.name)
Spacer()
Button(action: {
vm.request(action: .PSU, param: psu.name)
}, label: {
Text(psu.isOn ? "ON" : "OFF")
.foregroundColor(psu.isOn ? .green : .primary)
})
.accentColor(.white)
.frame(width: 40, alignment: .center)
Text(String(format: "%05.2f V", psu.voltage)).frame(width: 50, alignment: .trailing)
Text(String(format: "%05.2f A", psu.current)).frame(width: 50, alignment: .trailing)
}
}
}
Thanks again for all your time.
P.S. The same applies with Toggle, so I was forced to use a normal Button instead and simply change the colour of the the text to reflect the outcome. It would be impractical to replace a Picker with many values.
This is my SwiftUI interface - that's about to be junked.
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 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
})
}
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.
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?
Is it viable to use Microsoft's Visual Studio instead of relying on Xcode?
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.
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.
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.