Post

Replies

Boosts

Views

Activity

Incorrect results from `isSuperset` when used with specific emoji symbols and prefix.
Hi, It seams that the public func isSuperset(of other: CharacterSet) -> Bool API gives inconsistent results for some emoji symbols when uses with and without prefix text. Here is a playground example: import Foundation let input1 = "πŸ₯€" let input11 = "aπŸ₯€" let input2 = "πŸ˜€" let input22 = "aπŸ˜€" let letters = CharacterSet.letters print("'\(input1)' is part of 'CharacterSet.letters': \(letters.isSuperset(of: CharacterSet(charactersIn: input1)))") // Gives false print("'\(input11)' is part of 'CharacterSet.letters': \(letters.isSuperset(of: CharacterSet(charactersIn: input11)))") // INCORRECT: Should give false, but it gives true print("'\(input2)' is part of 'CharacterSet.letters': \(letters.isSuperset(of: CharacterSet(charactersIn: input2)))") // Gives false print("'\(input22)' is part of 'CharacterSet.letters': \(letters.isSuperset(of: CharacterSet(charactersIn: input22)))") // Gives false Output: 'πŸ₯€' is part of 'CharacterSet.letters': false 'aπŸ₯€' is part of 'CharacterSet.letters': true 'πŸ˜€' is part of 'CharacterSet.letters': false 'aπŸ˜€' is part of 'CharacterSet.letters': false Has anyone observed this?
5
0
366
Jan ’24
DocC: Is it possible to truly compile the tutorial's code and get compiler errors/warnings
The idea is to make it easer to update documentation when API changes or when code is not correct. Is it possible to make the code file declared like this: @Code(name: "AppDelegate.swift", file: AppDelegate.swift) And the content of the AppDelegate.swift file is: import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { compiler error should be raised here return true } } After doing "Product > Build Documentation" the output gives the following documentation and there is not warning or errors during the build: Thank you for your answers.
1
0
459
Dec ’23
Previously stopped "paste" into a UITextField causes "Shake to undo" raise `textField(_:shouldChangeCharactersIn:replacementString:)` with invalid range.
If you handle textField(_:shouldChangeCharactersIn:replacementString:) and return false for a paste operation, once user does and "shake to undo" the provided range is out of bounds of the text field's text. Is this expected? Here is a sample code that simply limits the input to 5 characters: class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var textField: UITextField! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. textField.delegate = self } func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let text = textField.text ?? "" let currentString = text as NSString let newString = currentString.replacingCharacters(in: range, with: string) return newString.count < 5 } } Steps to reproduce a the crash: UsernameTextFieldShake[40533:8359309] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds' Type "test" Copy the text Paste the text at the end of the text field's text The paste will not be allowed as it is above 5 length. Shake the device Press undo Crash, due to let newString = currentString.replacingCharacters(in: range, with: string) Is there a correct way to guard agains this "rogue" range? Is this range expected to be provided to the textField(_:shouldChangeCharactersIn:replacementString:), one might think because the previous handling returned false that the undo should happen on the previous accepted command (which was at step 1) Thank you for the responses.
0
0
339
Nov ’23
How to use `HKWorkoutBuilder` inside unit tests on iOS 17 and above
With iOS 17 creation of HKWorkout is deprecated via its init functions and the recommendation is to use HKWorkoutBuilder. If you try to init HKWorkout like you would pre iOS 17 you get this warning of deprecation: The problem is that I am creating this HKWorkout object inside unit tests in order to test a service that works with such objects. And HKWorkoutBuilder requires a HKHealthStore which itself requires to be authenticated to be able to create HKWorkoutActivity instances, like it would be when an app is running. But since the unit tests cannot accept the request on the HKHealthStore I am not sure if using HKWorkoutBuilder inside unit tests is possible. I've also tried to inherit HKHealthStore and override all of its methods, but still, store requires authorization. Any ideas on how to proceed with creating HKWorkout for unit test purposes?
0
1
392
Nov ’23
Disable "swipeActions" on only a specific row in a List
Hi, I want to enable swipeActions for some rows of a List while other rows do not have this action. Here is an example: List { ForEach(1..<100) { i in Text("\(i)") .swipeActions(edge: .leading) { Button { total += i } label: { Label("Add \(i)", systemImage: "plus.circle") } .tint(.indigo) } .swipeActions(edge: .trailing) { Button { total -= i } label: { Label("Subtract \(i)", systemImage: "minus.circle") } } } } What would be the best approach to disable the swipeActions for let say the 50 row?
1
0
446
Nov ’23
iOS 17: How to use `HKWorkoutBuilder` inside unit tests
Hi, with iOS 17 creation of HKWorkout is deprecated via its init functions and the recommendation is to use HKWorkoutBuilder: The problem is that I am creating this HKWorkout object inside unit tests in order to test a service that works with such objects. And HKWorkoutBuilder requires a HKHealthStore which itself requires to be authenticated to be able to create HKWorkoutActivity instances, like it would be when an app is running. But since the unit tests cannot accept the request on the HKHealthStore I am not sure if using HKWorkoutBuilder inside unit tests is possible. Any ideas on how to proceed with creating HKWorkout for unit test purposes?
0
1
413
Oct ’23
Xcode 15: Core Data : No NSValueTransformer with class name *** was found for attribute YYY on entity ZZZ for custom `NSSecureUnarchiveFromDataTransformer`
Hi, I am creating a custom NSSecureUnarchiveFromDataTransformer in order to handle attributes of entities of type NSDateComponents. It all works and I did not see any warnings in the "Issue navigator" inside Xcode but with Xcode 15 I started seeing this warning: /Users/.../CustomNSSecureUnarchiveFromDataTransformer/CoreData:1:1 no NSValueTransformer with class name 'CustomSecureUnarchiveFromDataTransformer' was found for attribute 'testDate' on entity 'Item' My use case is very simple, I have this custom transformer: @objc(CustomSecureUnarchiveFromDataTransformer) final class CustomSecureUnarchiveFromDataTransformer: NSSecureUnarchiveFromDataTransformer { override class var allowedTopLevelClasses: [AnyClass] { return [NSDateComponents.self] } static let name = NSValueTransformerName(rawValue: String(describing: CustomSecureUnarchiveFromDataTransformer.self)) public static func register() { let transformer = CustomSecureUnarchiveFromDataTransformer() ValueTransformer.setValueTransformer(transformer, forName: name) } } which is set to the Core data entity's "Transformer": which leads to the warning in Xcode 15. App works just fine and there are no problems during run time, but this warning is shown and I want to fix it. Here is a simple test project https://github.com/VladimirAmiorkov/CustomNSSecureUnarchiveFromDataTransformer
9
9
2.0k
Oct ’23