Posts

Post not yet marked as solved
1 Replies
322 Views
I'm trying to add a quick look preview extension to my app. But I can't find any reference on this On a earlier thread (https://developer.apple.com/forums/thread/704155) everyone seems to misunderstand my question. I MEAN THE QUICK LOOK YOU CAN TOGGLE IN FINDER THAT WILL SHOW YOU A PREVIEW OF A DOCUEMNT I don't want to add the tag QuickLook because that's not I want to do.
Posted Last updated
.
Post not yet marked as solved
0 Replies
289 Views
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.
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.2k Views
2022-06-09 08:51:30.793789+0800 MyAppName[4651:447798] [aqme]        MEMixerChannel.cpp:1629  client <AudioQueueObject@0x7fc09a04f400; [0]; play> got error 2003332927 while sending format information I use .mp3
Posted Last updated
.
Post not yet marked as solved
0 Replies
768 Views
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?
Posted Last updated
.
Post not yet marked as solved
3 Replies
1.4k Views
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 *** secs" after *** 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?
Posted Last updated
.
Post marked as solved
2 Replies
955 Views
SwiftUI's Refreshing mechanism is driving me crazy. Say that I have this view: NavigationView { List($datasource) { $item in NavigationLink { SubView(item: $item) } label: { Text(item.someAttribute) } } } SubView: TextField("Placeholder", text: $item.someAttribute) And each time I edit the value in the SubView, the SwiftUI's navigation controller retreats the view to the home page(the initial view). Why?
Posted Last updated
.
Post not yet marked as solved
2 Replies
731 Views
Without dependencies on other third-party frameworks Just a function that receives a string, outputs a string and throws
Posted Last updated
.
Post marked as solved
1 Replies
1.1k Views
I wrote an app that users can create utilities using terminal commands I'm experiencing a bug that's driving me crazy: I have an array of utilities, and by extension, I made Array<Utility> and Utility RawRepresantable: Part of the declaration for Utility public init?(rawValue: String) {     guard let data = rawValue.data(using: .utf8),           let result = try? JSONDecoder().decode(Utility.self, from: data)     else { return nil }     self = result } public var rawValue: String {     var encoder = JSONEncoder()     encoder.outputFormatting = .prettyPrinted     guard let data = try? encoder.encode(self),           let result = String(data: data, encoding: .utf8)     else {         return ""     }     return result } extension for Array<Utility> extension Array: RawRepresentable where Element: Codable {     public init?(rawValue: String) {         guard let data = rawValue.data(using: .utf8),               let result = try? JSONDecoder().decode([Element].self, from: data)         else { return nil }         self = result     }          public var rawValue: String {         let encoder = JSONEncoder()         encoder.outputFormatting = .prettyPrinted guard let data = try? encoder.encode(self),               let result = String(data: data, encoding: .utf8)         else {             return "[]"         }         return result     } } And now, because of some strange SwiftUI bug (FB11401294) When I pass a binding down a view hierarchy such as List or ForEach they update weirdly. I implement an "edit" feature for my utilities so I will not directly use binding but to call a function that takes an inout of Array<Utility>, the original item, and the item after being edited: func replace(_ sequence: inout [Utility], item: Utility, with replace: Utility) {     var raw = sequence.rawValue     print(raw)     let rawReplaced = raw.replacingOccurrences(of: item.rawValue, with: replace.rawValue)     print(item.rawValue, replace.rawValue)     print(rawReplaced)     sequence = [Utility].init(rawValue: sequence.rawValue.replacingOccurrences(of: item.rawValue, with: replace.rawValue))!     print(sequence) } And the problem is it works and after implementing another completely different feature it stopped working from my debugging, the input of the function is correct and the problem is inside the function. But, as the error seems to be on this line: sequence = [Utility].init(rawValue: sequence.rawValue.replacingOccurrences(of: item.rawValue, with: replace.rawValue))! Now i have completely no idea why this works last time and won't now This line of code works completely well in playgrounds and is now freaking me out Help anyone?
Posted Last updated
.
Post not yet marked as solved
0 Replies
625 Views
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?
Posted Last updated
.
Post not yet marked as solved
1 Replies
659 Views
// 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?
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.1k Views
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?
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.8k Views
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)
Posted Last updated
.