Post

Replies

Boosts

Views

Activity

Battery level with IOPSCopyPowerSourcesList
I want to get battery level, estimated remaining time, battery health...etc via IOPSCopyPowerSourcesList Not sure how I'm not experienced with pointers...     func updateBatteryView() {         let battery = IOPSCopyPowerSourcesInfo().takeRetainedValue()         let info = IOPSCopyPowerSourcesList(battery).takeRetainedValue() // Now what?     }
1
0
1.5k
Aug ’22
Keychain Access
I'm trying to get the password of the current user's wifi. I'm trying the Security framework mentioned by @eskimo here, but it's not working. I'm trying the CLI command public func getPassword(ssid: String) -> String? {     let command = "security find-generic-password -l \"\(ssid)\" -D 'AirPort network password' -w"     let result = shell(command)     return result } private func shell(_ command: String, lauchPath: String = "/bin/zsh") -> String? {     let task = Process()     let pipe = Pipe()          task.standardOutput = pipe     task.standardError = pipe     task.arguments = ["-c", command]     task.launchPath = "/bin/zsh"     task.launch()          let data = pipe.fileHandleForReading.readDataToEndOfFile()     let output = String(data: data, encoding: .utf8)?         .trimmingCharacters(in: .newlines)          return output } I'm now trying AppKit so I declared: @IBOutlet var passwordLabel: NSTextField! var password: String? var wifi: String? ... // applicationDidFinishLaunching(_ aNotification:) wifi = CWWiFiClient.shared().interface()?.ssid() .... password = getPassword(ssid: wifi ?? "Unknown") passwordLabel.stringValue = password ?? "ERROR" in applicationDidFinishLaunching(_ aNotification:) it worked. Note: on my dialog, there's only Deny and Allow, not Deny, Allow Once, Always Allow I added a refresh button next to the password label and it won't work when I press the button: @IBAction func RefreshPassword(_ sender: NSButton) {     wifi = CWWiFiClient.shared().interface()?.ssid()     password = getPassword(ssid: wifi)     print(password)     if let i = wifi {         DeviceWiFiLabel.stringValue = i         DeviceWiFiLabel.textColor = .systemGreen         passwordLabel.textColor = .textColor     } else {         DeviceWiFiLabel.stringValue = "None"         DeviceWiFiLabel.textColor = .systemOrange         passwordLabel.textColor = .red     } passwordLabel.stringValue = password ?? "ERROR" } The dialog still pops open but I can't enter text when the textfield is focused, that is, no text appears when I hit a key when textfield focused. When I dismiss using the "Deny" button, sometimes a message like these appears in the console: 2022-08-24 05:21:24.034479+0800 MyApp[22457:564086] Detected potentially harmful notification post rate of <some sort of float-point number that always changes and about 300) notifications per second I can't always reproduce the issue. Any idea why?
1
0
1.3k
Aug ’22
Get memory usage
I'm trying to get the memory usage of the entire system. // referance: https://www.jb51.cc/iOS/590624.html public func memsize() -&gt; UInt64 {     var taskInfo = mach_task_basic_info()     var count = UInt32(MemoryLayout&lt;mach_task_basic_info&gt;.size)     let kerr: kern_return_t = withUnsafeMutablePointer(to: &amp;taskInfo) {         $0.withMemoryRebound(to: integer_t.self,capacity: 1) {             task_info(mach_task_self_,task_flavor_t(MACH_TASK_BASIC_INFO),$0,&amp;count)         }     }       if kerr == KERN_SUCCESS {         return taskInfo.resident_size     }     return 0 } not working, apparently. When my system uses 15 GB it shows it's below 1 GB. Do anyone have other ways to get memory usage of the device (better macOS)
1
0
2.1k
Aug ’22
Strange addition
// I have a object "CentralProcesser". I can get the user and system usage of the CPU. I want to get the total. let system: Double = CentralProcesser.current.usage.system // 10.8746757975 or something like that let user: Double = CentralProcesser.current.usage.user // 23.24123412424 or something like that // And now I add them together, right? let total: Double = system + user // nan Why?
1
0
865
Aug ’22
Enumerate the child view of a View
If we have this SwiftUI View: Text("Hello") Image("Some Image") We have two Views, and we refract them into a single one: struct MyView: View { var body: some View { Text("Hello") Image("Some Image") } } If we use it in most cases, it is ordered into an implicit VStack. But, if we do this: List { MyView() } SwiftUI will automatically split MyView into two separate Views. My question is that if I have this: @ViewBuilder func pageView(_ views: () -> View) -> View { } How can I enumerate the child Views of the variable view just like in List?
0
0
814
Aug ’22
Delayed Return in Swift
So I have an app that users can create utilities with some shell script I have a feature that the user can experiment with their scripts (a shell REPL) But if I type zsh in the REPL the whole app went stuck and the zsh shell outputs in Xcode: (This is my zsh theme) I've added detection for these: But what I really want is to let the process run in the background while the REPL output "Time out waiting for pipeline output after xxx secs" after xxx secs I've thought about letting them run in two separate asynchronous tasks so that if one task was completed it could first return the function but I just can't manage it: func run(launchPath: String? = nil, command: String) -> String { let task = Process() let pipe = Pipe() task.standardOutput = pipe task.standardError = pipe task.arguments = ["-c", command] task.launchPath = launchPath ?? "/bin/zsh/" task.launch() Task { let data = try? pipe.fileHandleForReading.readToEnd()! return String(data: data!, encoding: .utf8)! } DispatchQueue.main.asyncAfter(deadline: .now + 30) { return "Time out" // ERROR } } So How can I create two separate asynchronous tasks, one receiving the pipe output, and one, after a few seconds, returns the function?
3
0
1.9k
Sep ’22
iPhone 14 Pro Series Simulator bug
I wrote a macOS app and I added iPhone support Now it looks like this: I thought it was some sort of .frame or sth like that I've accidentally added But then I started with a fresh macOS project and added iPhone support, and now it's still like that: I reckon that's because I've set the target os to iOS 15.4 because when I update to 16 there's no problem Is it because Xcode can't compile UI for a 14 pro's screen for below iOS 16? But then again, why does the preview work?
0
0
937
Oct ’22
How to present a UIViewController in a SKScene
I'm trying to integrate AR into my app, and I want to be able to present a the UIViewController containing the ar view after pressing a sprite in SKScene. I'm trying to look for a way to present this view controller in touchesBegan however I'm not able to find any reference on this. I'd really appreciate any help.
0
0
673
Feb ’24
Stuck
I have a big problem with an AI app. It's supposed to give me a color according to the text entered into a TextField. But every time it gives me the same output. I'm new in developing, and I know it must be a tiny bug but I just couldn't find out why. Should I just ... paste all of my code here? I can't upload a .zip :(
6
0
556
May ’22
NSOpenPanel malfunctioning
I have a app that needs to have a "choose file" function and I used a button hooked up to a function using NSOpenPanel to do that. But after I tried to add a drag&drop action, it wont work anymore. I revert all my files to the version when the NSOpenPanel work, but it's still the same. I also tried to restart my computer, all the same. Here's my function: private func selectFile() {         let openPanel = NSOpenPanel()         openPanel.canChooseDirectories = false         openPanel.allowsMultipleSelection = false         openPanel.begin { response in             if response == .OK {                 self.url = openPanel.url             }         }     } should I file a bug? should I reinstall xcode?
1
0
473
May ’22
Strange bug
My SceneKit Game failed with a com.apple.scenekit.scnview-renderer (10): signal SIGABRT The error was marked on the line @main Here's the log navigator: 2022-05-25 15:24:18.829319+0800 MyWorldiOS[9022:293392] Metal API Validation Enabled validateRenderPassDescriptor:899: failed assertion `RenderPass Descriptor Validation MTLRenderPassAttachmentDescriptor MTLStoreActionMultisampleResolve store action for the depth attachment is not supported by device PixelFormat MTLPixelFormatDepth32Float cannot be a MSAA resolve target ' dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_LIBRARY_PATH=/Users/wangkeshijian/Library/Developer/Xcode/DerivedData/MyWorld-aayoxjgvyfzbxvgqnvylzgvlwkyr/Build/Products/Debug-iphonesimulator:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib DYLD_FRAMEWORK_PATH=/Users/wangkeshijian/Library/Developer/Xcode/DerivedData/MyWorld-aayoxjgvyfzbxvgqnvylzgvlwkyr/Build/Products/Debug-iphonesimulator validateRenderPassDescriptor:899: failed assertion `RenderPass Descriptor Validation MTLRenderPassAttachmentDescriptor MTLStoreActionMultisampleResolve store action for the depth attachment is not supported by device PixelFormat MTLPixelFormatDepth32Float cannot be a MSAA resolve target ' CoreSimulator 802.6 - Device: MyPhone (EBB1ECDE-8AD7-4418-84AF-0B761E0A2EA7) - Runtime: iOS 15.4 (19E5234a) - DeviceType: iPhone 12 (lldb)  I'm not sure what else should I put in here
1
0
983
May ’22