Post

Replies

Boosts

Views

Activity

Xcode Cloud to use swift 5.7 (Xcode-14)
Overview I have an existing Xcode project that works fine with Xcode Cloud I have a separate branch on to which I have migrated and made changes for Xcode 14 On the same branch I have made some code changes that is supported by Swift 5.7 Example: var price: Int? = 100 guard let price else { return } Problem Xcode code build fails with the error Variable binding in a condition requires an initializer Question: Is it possible to build Xcode Cloud on Swift 5.7 or Xcode 14?
0
0
1.1k
Jul ’22
Lab appointment - Pending status
Hi, My lab appointment status is pending. The lab is for tomorrow. When would I get to know if my lab appointment has been accepted. It is my first time for a lab appointment, also I forgot to mention the feedback IDs, would there be a way to amend the request to include the feedback IDs if that would help. (Feedback assistant was down when I booked an appointment so couldn't get the feedback IDs.) Any help would be much appreciated as I am from a different timezone and would need to plan accordingly .... really praying I get an appointment
1
0
1.1k
Jun ’22
Swift Concurrency (async let) - Cancellation
I am a bit confused about tasks being cancelled. Overview: checkCancellation function has 2 child tasks: computeA and computeB that run concurrently, computeB throws an error. Doubt: I expected child task computeA to be cancelled because computeB threw an error, but computeA was never cancelled. Is my understanding wrong or am I missing something? Or is this a bug? Note: I am using a SwiftUI project (as Swift Playgrounds don't support async let) macOS Big Sur 11.5.2 (20G95) Xcode Version 13.0 beta 5 (13A5212g) Output: A - started B - going to throw A - going to return, Task.isCancelled = false error: infinity Concurrent Function Definitions: import Foundation import UIKit enum ComputationError: Error { case infinity } fileprivate func computeA() async throws -> Int { print("A - started") await Task.sleep(2 * 100_000_000) print("A - going to return, Task.isCancelled = \(Task.isCancelled)") //I expected Task.isCancelled to be true return 25 } fileprivate func computeB() async throws -> Int { print("B - going to throw") throw ComputationError.infinity } func checkCancellation() async throws { async let a = computeA() async let b = computeB() let c = try await a + b print("c = \(c)") } Invoking Concurrent function struct ContentView: View { var body: some View { Button("check cancellation") { Task { do { try await checkCancellation() print("normal exit") } catch { print("error: \(error)") } } } } }
4
0
1.4k
Dec ’21
@FocusedBinding not working for iOS (using it for Commands)
Aim To use a keyboard shortcut on a Multiplatform app (iOS and macOS) When keyboard shortcut is tapped, the price needs to be printed Problem The same code doesn't work on iPad but works on macOS Question: Why is not working? How to fix this? Environment macOS Big Sur - 11.6 (20G165) Version 13.0 (13A233) Code @main struct TestApp: App { @State private var price = 0 var body: some Scene { WindowGroup { ContentView(price: $price) .focusedValue(\.price, $price) } .commands { PriceCommands() } } } struct ContentView: View { @Binding var price: Int var body: some View { IncreasePriceButton(price: $price) } } struct IncreasePriceButton: View { @Binding var price: Int var body: some View { Button("Increase Price") { price += 1 print("price = \(price)") } } } struct PriceCommandButton: View { @FocusedBinding(\.price) var price var body: some View { Button("Print Price") { print("price = \(price)") } } } struct PriceCommands: Commands { var body: some Commands { CommandMenu("Custom") { PriceCommandButton() .keyboardShortcut(KeyboardShortcut("C", modifiers: [.command, .shift])) } } } struct FocusedPriceKey: FocusedValueKey { typealias Value = Binding<Int> } extension FocusedValues { var price: FocusedPriceKey.Value? { get { self[FocusedPriceKey.self] } set { self[FocusedPriceKey.self] = newValue } } }
1
0
924
Oct ’21
Binding value from an ObservableObject
Aim:I have a model which is an ObservableObject. It has a Bool property, I would like to use this Bool property to initialise a @Binding variable.Questions:How to convert an @ObservableObject to a @Binding ?Is creating a @State the only way to initialise a @Binding ?Note:I do understand I can make use of @ObservedObject / @EnvironmentObject, and I see it's usefulness, but I am not sure a simple button needs to have access to the entire model.Or is my understanding incorrect ?Code:import SwiftUI import Combine import SwiftUI import PlaygroundSupport class Car : ObservableObject { @Published var isReadyForSale = true } struct SaleButton : View { @Binding var isOn : Bool var body: some View { Button(action: { self.isOn.toggle() }) { Text(isOn ? "On" : "Off") } } } let car = Car() //How to convert an ObservableObject to a Binding //Is creating an ObservedObject or EnvironmentObject the only way to handle a Observable Object ? let button = SaleButton(isOn: car.isReadyForSale) //Throws a compilation error and rightly so, but how to pass it as a Binding variable ? PlaygroundPage.current.setLiveView(button)
3
5
24k
Sep ’21
Extract Data from P8 file
Hi,I am trying to extract the data from the P8 file to use it generate JWT.I understand that it is possible using dumpasn1 and extracting the OCTET STRING section. This is great, and is definitely possible.I was wondering if it was possible to do it on macOS using Apple's APIs (example SecItemImport), would make it simpler if it was possible all in the mac app.I tried the following but it didn't work:Error: I got the OSStatus as -25257Questions:- Is there a way to do this using SecItemImport or any other Apple APIs as I am using it in a command line mac app ?- Are the parameters to SecItemImport are incorrect ?- Am down the wrong path? , any direction to the correct API would help.What I tried with SecItemImport:- Data extracted from the file- Decoding the data from the file- Some input formatsMany thanks.import Foundation import Security func f1() { do { let fileURL = URL(fileURLWithPath: "some valid path"); let data = try Data(contentsOf: fileURL) guard let string = String(data: data, encoding: .utf8) else { print("Failed to convert data to string") return } let b64Text = string .replacingOccurrences(of: "-----END PRIVATE KEY-----", with: "") .replacingOccurrences(of: "-----BEGIN PRIVATE KEY-----", with: "") .replacingOccurrences(of: "\n", with: "") guard let b64Data = b64Text.data(using: .utf8), let decodedData = Data(base64Encoded: b64Data) else { print("Was not b64 data") return } print(string) var outArray : CFArray? let filename : CFString? = nil var inputFormat = SecExternalFormat.formatUnknown var itemType = SecExternalItemType.itemTypePrivateKey let flags = SecItemImportExportFlags() //I tried data, b64Data, decodedData all seems to return an error let status = SecItemImport(decodedData as CFData, filename, &amp;inputFormat, &amp;itemType, flags, nil, nil, &amp;outArray) //status = -25257 print("status = \(status)") for element in (outArray as [AnyObject]?) ?? [] { print("element = \(element)") } } catch { print("Error: \(error)") } } f1()
4
0
5.9k
May ’21