you can use a process class
Post
Replies
Boosts
Views
Activity
this is already how my code is structured. I got this same response from chat gpt it still doesn't solve the contentview() scope error that I get in the App.swift file
The error doesn’t get generated in this file aka the ContentView.swift file but instead xcode brings up the default App.swift file(in my case its Mac_GPTApp.swift) and shows a “Cannot find ContentView() in scope” error for the line ContentView().
@eskimo @Polyphonic UPDATE: here is my updated code that some of you were requesting. I have the updated methods implemented but im getting the error "Cannot convert return expression of type 'Double' to return type 'String?'"
import Foundation
class RAMUsage {
let processInfo = ProcessInfo.processInfo
func getRAM() {
let physicalMemory = processInfo.physicalMemory
let formatter = ByteCountFormatter()
formatter.countStyle = .memory
let formattedMemoryUsage = formatter.string(fromByteCount: Int64(physicalMemory))
parseAndPrint(formattedMemoryUsage: formattedMemoryUsage)
}
func parseAndPrint(formattedMemoryUsage: String) {
print("Formatted RAM usage: \(formattedMemoryUsage)")
if let gigsOfRAM = parseFormattedRAMUsage(formattedUsage: formattedMemoryUsage) {
print("RAM Usage in Gigabytes: \(gigsOfRAM) GB")
} else {
print("Could not retrieve or parse RAM usage")
}
}
func parseFormattedRAMUsage(formattedUsage: String) -> Double? {
let scanner = Scanner(string: formattedUsage)
var value: Double = 0.0
var unit: NSString?
if let scannedValue = scanner.scanDouble(representation: .decimal) {
value = scannedValue
func scanCharacters(from set: CharacterSet) -> String? {
if let unitString = unit as String?, unitString.lowercased() == "GB" {
print("Parsed RAM Usage: \(value) GB")
return value
} else {
print("could not parse and return value")
}
}
return nil
}
}
}
im running into the exact same issue. I'm on Sonoma and on Xcode 15
thank you!
Hi friends, I was able to fix this issue by going to Xcode, settings, platforms, and simply un installing iOS 17.4 runtime and reinstalling it then re-launching Xcode and cleaning the build folder, it solved the issue.
@Claude31 so My .onAppear should be called in the same place as my List()? since it’s in my ZStack?