Post

Replies

Boosts

Views

Activity

Please tell me why licenceUrl is nil???
I want to open a text file where all the Licence stuff is written down, I want to do it like this in a macOS app, but the app Bundle does not work for some reason: import SwiftUI @main struct menuHelpApp: App {       func androidTools(tool: URL, arguments: [String], completionHandler: @escaping (Int32, Data) -> Void) throws {         let group = DispatchGroup()         let pipe = Pipe()         var standardOutData = Data()         group.enter()         let proc = Process()         proc.executableURL = tool         proc.arguments = arguments         proc.standardOutput = pipe.fileHandleForWriting         proc.terminationHandler = { _ in             proc.terminationHandler = nil             group.leave()         }         group.enter()         DispatchQueue.global().async {             let data = pipe.fileHandleForReading.readDataToEndOfFile()             pipe.fileHandleForReading.closeFile()             DispatchQueue.main.async {                 standardOutData = data                 group.leave()             }         }         group.notify(queue: .main) {             completionHandler(proc.terminationStatus, standardOutData)         }         try proc.run()         pipe.fileHandleForWriting.closeFile()     }       var body: some Scene {         WindowGroup {             ContentView()         }         .commands {             CommandGroup(replacing: .help) {                 let licenceUrl = Bundle.main.url(forResource: "textFiles/Licence", withExtension: "txt")                 Button(action: {                     try! androidTools(tool: URL(fileURLWithPath: "/usr/bin/open", relativeTo: nil), arguments: ["-a", "TextEdit", licenceUrl!.absoluteString]) { (status, outputData) in                         let output = String(data: outputData, encoding: .utf8) ?? ""                         print(output)                     }                 }) {                     Text("AppSignerGui License")                 }             }         }     } }
5
0
578
Aug ’21
How to save return value from function in swift ui and use it
My app has two buttons, the first is calling a function that return a string and does some other stuff. The second button has a function that takes the return String from the function one. Because the first function does other stuff as well, how can I store the return String in a variable for button two, so I don't have to call the function? Example below, I want to avoid usingDirString (strUpper: returnDirString()) func returnDirString () -> String {     let dir = "/some/return/string"     return dir } func usingDirString (strUpper: String) {     print(strUpper) } struct ContentView: View {     var body: some View {         Button(action: {             returnDirString()         }) {             Text("First")         }         .padding()         Button(action: {             usingDirString (strUpper: returnDirString())         }) {             Text("second")         }         .padding()     } }
2
0
592
Jul ’21
Please tell me why licenceUrl is nil???
I want to open a text file where all the Licence stuff is written down, I want to do it like this in a macOS app, but the app Bundle does not work for some reason: import SwiftUI @main struct menuHelpApp: App {       func androidTools(tool: URL, arguments: [String], completionHandler: @escaping (Int32, Data) -> Void) throws {         let group = DispatchGroup()         let pipe = Pipe()         var standardOutData = Data()         group.enter()         let proc = Process()         proc.executableURL = tool         proc.arguments = arguments         proc.standardOutput = pipe.fileHandleForWriting         proc.terminationHandler = { _ in             proc.terminationHandler = nil             group.leave()         }         group.enter()         DispatchQueue.global().async {             let data = pipe.fileHandleForReading.readDataToEndOfFile()             pipe.fileHandleForReading.closeFile()             DispatchQueue.main.async {                 standardOutData = data                 group.leave()             }         }         group.notify(queue: .main) {             completionHandler(proc.terminationStatus, standardOutData)         }         try proc.run()         pipe.fileHandleForWriting.closeFile()     }       var body: some Scene {         WindowGroup {             ContentView()         }         .commands {             CommandGroup(replacing: .help) {                 let licenceUrl = Bundle.main.url(forResource: "textFiles/Licence", withExtension: "txt")                 Button(action: {                     try! androidTools(tool: URL(fileURLWithPath: "/usr/bin/open", relativeTo: nil), arguments: ["-a", "TextEdit", licenceUrl!.absoluteString]) { (status, outputData) in                         let output = String(data: outputData, encoding: .utf8) ?? ""                         print(output)                     }                 }) {                     Text("AppSignerGui License")                 }             }         }     } }
Replies
5
Boosts
0
Views
578
Activity
Aug ’21
How to save return value from function in swift ui and use it
My app has two buttons, the first is calling a function that return a string and does some other stuff. The second button has a function that takes the return String from the function one. Because the first function does other stuff as well, how can I store the return String in a variable for button two, so I don't have to call the function? Example below, I want to avoid usingDirString (strUpper: returnDirString()) func returnDirString () -> String {     let dir = "/some/return/string"     return dir } func usingDirString (strUpper: String) {     print(strUpper) } struct ContentView: View {     var body: some View {         Button(action: {             returnDirString()         }) {             Text("First")         }         .padding()         Button(action: {             usingDirString (strUpper: returnDirString())         }) {             Text("second")         }         .padding()     } }
Replies
2
Boosts
0
Views
592
Activity
Jul ’21