Post

Replies

Boosts

Views

Activity

WeatherKit and SwiftUI
I'm trying out weather kit and I'm using swiftUI I have a view that accepts a CurrentWeather type value in initailizer I cannot find a way to initialize a CurrentWeather How can I preview It? This won't work: // forecaster and forecast is defined by me struct WeatherView_Previews: PreviewProvider {     static var previews: some View { // <- static WeatherView(weather: await forecaster.forcast(latitude: 0, longtitude: 0)) // <- concurrency     } }
1
0
1k
Jun ’22
@AppStorage
I have a structure TodoItem struct TodoItem: Codable, Hashable, Identifiable {     var id: UUID = UUID()     var item: String     var done: Bool = false } How can I use AppStorage on [TodoItem]?
1
0
1.3k
Jul ’22
Pass on Binding
I have this: struct TableRow: View { @Binding var data: TodoItem var body: some View { ... } } and this: List {     ForEach(data) { datum in         TableRow(data: ???) // <- what goes here?             .swipeActions {                 Button(role: .destructive) {                     data.delete(datum)                 } label: {                     Label("Delete", systemImage: "trash")                 }           }     } }
1
0
384
Jun ’22
I have a bug in Regex(maybe)
Feedback is filed. Trying to look into the Core.swift. diagnostics: Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:  ---------------------------------------- CrashReportError: Fatal Error in Core.swift UtilityScript crashed due to fatalError in Core.swift at line 77. 'try!' expression unexpectedly raised an error: Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:  ))' Process: UtilityScript[3141] Date/Time: 2022-07-02 03:56:17 +0000 Log File: <none> Application Specific Information:     dyld [         dyld config: DYLD_LIBRARY_PATH=/Users/wangkeshijian/Library/Developer/Xcode/DerivedData/UtilityScript-frovasvohxblobefzbrrwtvqtyuu/Build/Intermediates.noindex/Previews/UtilityScript/Products/Debug DYLD_FRAMEWORK_PATH=/Users/wangkeshijian/Library/Developer/Xcode/DerivedData/UtilityScript-frovasvohxblobefzbrrwtvqtyuu/Build/Intermediates.noindex/Previews/UtilityScript/Products/Debug     ]     libswiftCore.dylib [         _StringProcessing/Core.swift:77: Fatal error: 'try!' expression unexpectedly raised an error: Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:  ))'         /AppleInternal/Library/BuildRoots/0cc5e7ad-e86f-11ec-ac50-3e2aa58faa6a/Library/Caches/com.apple.xbs/Sources/swiftlang_overlay_Platform/swift-experimental-string-processing/Sources/_StringProcessing/ConsumerInterface.swift:200     ]
1
0
838
Jul ’22
Strange cursor
macOS Ventura 13 beta 2 I'm coming over with a really strange issue with my cursor. It'd move toward the right-down by itself one pixel a time: right down right down It really freaked me out *laugh* I'll try attaching a video. FB submitted.
1
0
431
Jul ’22
Preview Crash (Shooed I fille a bug?)
I've just bought a M2 MacBook Pro, and my Timer app is giving me strange crash logs. Here's my code: struct ContentView: View {     @State var process: Any? = nil     @AppStorage("time") var time = 0     @State var timePassed = 0     @State var timer: Timer.TimerPublisher = Timer.publish(every: 1, on: .main, in: .common)     @State var cacheSecondsString: String  = String(UserDefaults.standard.integer(forKey: "time"))     @State var startTheTimer: Bool = false     var body: some View {         ZStack {             TimerView(time: $timePassed, total: $time).padding()             VStack {                 TextField("Time...", text: $cacheSecondsString)                     .font(.system(size: 35, weight: .light, design: .rounded))                     .multilineTextAlignment(.center)                     .onSubmit {                         time = Int(cacheSecondsString) ?? time                         cacheSecondsString = String(time)                     }                     .textFieldStyle(.plain)                     .padding()                     .fixedSize()                 Button {                     withAnimation {                         startTheTimer.toggle()                     }                 } label: {                     Label(startTheTimer ? "Stop" : "Start", systemImage: startTheTimer "stop.fill" : "clock").foregroundColor(.accentColor)                 }.buttonStyle(.plain).padding()             }         }.onChange(of: startTheTimer) { start in             if start {                 process = timer.connect()             } else {                 (process! as! Cancellable).cancel()             }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()             .previewDevice("iPad Air (5th generation)")     } } When I sort of "run" the preview (pressing on the play.circle button on top of my preview and press the button the second to deactivate my timer, a crash dialog appear, the standard one macOS uses when any process crashed, but the preview didn't crash.
1
0
455
Aug ’22
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