Post

Replies

Boosts

Views

Activity

Reply to Swift 6 conversion for IBOutlet
@eskimo that was when testing with Swift6 and Xcode 16.4. But after encapsulating the code using IBOutlet in MainActor.assumeIsolated({ // using textField.text }) I could remove the nonIsolated declaration for IBOutlet and get it working. Unfortunately, I've not kept a version to reproduce the error. In any case, I will not switch to Swift6 before using Xcode 26.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’25
Reply to Crash in Swift 6 when using UNUserNotification
@Engineer Thanks for reply. Some more crash info. On simulator (did not test on device at this stage). Here is crash report: Error occurs in #4 notifyMe IBAction @IBAction func notifyMe(_ sender: UIButton) { let center = UNUserNotificationCenter.current() center.delegate = self center.getNotificationSettings(completionHandler: { (settings) in if settings.authorizationStatus == .notDetermined { center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in DispatchQueue.main.async { if !granted { // Alert user } } } } else if settings.authorizationStatus == .denied { DispatchQueue.main.async { // Alert user } } else if settings.authorizationStatus == .authorized { DispatchQueue.main.async { self.alarmButton.isHidden = self.duree <= 120 } } }) var alertStyle = UIAlertController.Style.alert let alertController = UIAlertController( title: NSLocalizedString("M'avertir", comment: ""), message: NSLocalizedString("Attention", comment: ""), preferredStyle: alertStyle) var title = NSLocalizedString("5'", comment: "") let ok = UIAlertAction(title: title, style: .default, handler: {(action) -> Void in self.sendInitialNotification(beforeEnd: 5) DispatchQueue.main.async { sender.isHidden = true } }) alertController.addAction(ok) let cancelAction = UIAlertAction(title: NSLocalizedString("Non", comment: ""), style: .default, handler: { (action) -> Void in alertController.addAction(cancelAction) present(alertController, animated: true, completion: nil) } Crash apparently occurs on calling userNotificationCenter: nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { if notification.request.identifier == requestIdentifier { completionHandler( [.alert,.sound,.badge]) } }
Aug ’25
Reply to Swift 6 conversion for IBOutlet
Thanks Quinn. I removed the nonisolated for IBOutlet. But, as shown in your example, I had to mark all func în a class that uses UNUserNotificationCenterDelegate as nonIsolated, such as nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) I also note in your example that you marked response for didReceive as async. I tried to, but got the error: Instance method 'userNotificationCenter(_:didReceive:withCompletionHandler:)' nearly matches optional requirement 'userNotificationCenter(_:didReceive:withCompletionHandler:)' of protocol 'UNUserNotificationCenterDelegate' with the advice to Make 'userNotificationCenter_:didReceive:withCompletionHandler:)' private to silence this warning Converting to Swift 6 is definitely not an easy ride… I'll do extensive testing.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’25
Reply to Crash in Swift 6 when using UNUserNotification
Thanks for the answer. didReceive was already non isolated. So problem likely does not come from here. For willPresent, if I don't make it nonIsolated, I get an Xcode 16.4 compiler error: Main actor-isolated instance method 'userNotificationCenter(_:willPresent:withCompletionHandler:)' cannot be used to satisfy nonisolated requirement from protocol 'UNUserNotificationCenterDelegate' n Xcode 26, no error in func declaration if I remove nonIsolated. But error at UIViewController class definition level Conformance of 'CalcViewController' to protocol 'UNUserNotificationCenterDelegate' crosses into main actor-isolated code and can cause data races
Aug ’25
Reply to Swift 6 conversion for IBOutlet
MainActor.assumeIsolated seems the simplest way to go. I have noticed an important point when converting to Swift 6 which may help others. At some point, I had nearly 200 errors… Don't panic they say… Problem was that errors kept coming and disappearing. Just as if the compiler was a bit lost (and me with him) with all the changes occurring on classes or func (such as declaring MainActor or non isolated). This made error correction pretty erratic. I did a Clean build folder, and the number of errors dropped to less than 10.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’25
Reply to Range For Keys and Values Of Dictionary
You may build something custom. Just for illustration: typealias FruitDict = [String: (String, Int)] let myFruitBasket : FruitDict = ["apple":("red", 1), "banana": ("yellow", 2), "budbeeri": ("dark violet", 3), "chikoo": ("brown", 4)] func subBasket(_ basket: FruitDict, range: ClosedRange<Int>) -> [String: String] { let filtered = basket.filter { $0.value.1 >= range.lowerBound && $0.value.1 <= range.upperBound } let sub = filtered.mapValues{ value in value.0 } return sub } let sub: [String: String] = subBasket(myFruitBasket, range: 1...3) print(sub) print("keys: ", sub.keys) print("values", sub.values) You get: ["banana": "yellow", "apple": "red", "budbeeri": "dark violet"] keys: ["banana", "apple", "budbeeri"] values ["yellow", "red", "dark violet"] Of course, that's not ordered (order does not mean anything with dictionaries), as Quinn explained. But if you plan to use the result as a dictionary, that doesn't matter. To get ordered, you have to convert to array. Or you can compute: let sortedKeys = sub.keys.sorted() print("sorted keys: ", sortedKeys) for key in sortedKeys { print("sorted values", sub[key] ?? "") } And get sorted keys: ["apple", "banana", "budbeeri"] values red values yellow values dark violet
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’25
Reply to Using Dynamic Member Lookup in a Superclass
Interesting question (would like to see the solution), so my 1 cent contribution. Sorry if it is worthless. In The Swift Programming Language (Swift 5.7) : struct Point { var x, y: Int } @dynamicMemberLookup struct PassthroughWrapper<Value> { var value: Value subscript<T>(dynamicMember member: KeyPath<Value, T>) -> T { get { return value[keyPath: member] } } } let point = Point(x: 381, y: 431) let wrapper = PassthroughWrapper(value: point) print(wrapper.x) Have you tried to mimic this, by adding a value property in ElectronicComponent and calling PassthroughWrapper(value: resistorA) ?
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’25
Reply to How to publish medical app being a sole proprietorship?
has not responded to my request to switch to an organization account Who did you ask ? Did you contact support for help ? If that may help: https://help.uscreen.tv/en/articles/8284333-convert-apple-developer-account-from-individual-to-business https://ptwired.zendesk.com/hc/en-us/articles/360046161214-Change-your-Apple-Developer-Account-from-Individual-to-Organization
Aug ’25