Post

Replies

Boosts

Views

Created

Implementing a RandomNumberGenerator for testing
Back in the Swift 4 days, I implemented a RandomNumberGenerator for the purpose of testing, which is to say, it always returns the same sequence of UInt64's, so that I can validate code that accepts a RandomNumberGenerator. However, as of "circa" Swift 5, this test is reliably failing, because even though it returns a different number in the next function, it fails to return any element except the first one from arrays (sequences, etc.). Sample code is here: class MockRandomNumberGenerator: RandomNumberGenerator {     var current: UInt64 = 0     func next() -> UInt64 {         defer { current += 1 }         return current     } } var mockRandomNumberGenerator = MockRandomNumberGenerator() let testArray = 0..<10 for _ in 0..<testArray.count {     print("testArray.randomElement   : \(testArray.randomElement(using: &mockRandomNumberGenerator)!)")     print("testArray[Int.random(...)]: \(testArray[Int.random(in: 0..<testArray.count, using: &mockRandomNumberGenerator)])") } The output of this is always 0, for every iteration. I expected the sequence to be returned in order, from 0 to 9. So, it fails in the same way for both array randomElement() and range random(in:). Prior to Swift 5, this same implementation returned the sequence in order. What do I need to do in the random number generator implementation to get it to work with arrays (and ranges) correctly?
2
0
805
Aug ’21
iPad-on-macOS (Catalyst) and menu bar localization
Hi,I have a confounding localization problem for the menu bar and preferences in an iPad-on-macOS (Catalyst) app.Here is all I did to find the problem. I checked the Mac checkbox for an existing, shipping app that contains 10 localizations, and I added the default menu bar to its Main.storyboard file. The Main.storyboard file is not localized, as I replace all app-specific strings at runtime by calling NSLocalizedString directly. I also have a Settings bundle localized to the same 10 languages.The first problem I observed was, the menu bar items that refer to the app name (such as About, Quit, etc.), appear in ALL-CAPS (e.g., NSMENUITEMTITLEABOUT, etc.):The menu bar menu title for the app is correct, but it appears to not substitute the app name in any menu items that require it. The rest of the application (main window contents) localizes as expected.If I select a different region and language to run, all of the CamelCase menu items (Preferences, Services, etc.) appear localized, but the all-caps items are still not localized.I tried changing the storyboard file to have localization (Base, and all of the app's supported locales), but it had no effect. I also observed that if I add my own menu items using the same string keys found in my Localization.strings files, and ensure that the storyboard is using those localization files, my app-specific menu items are also not being localized. Only the system menu items without the app name are being localized.Lastly, I observed that the Preferences window's strings are also entirely in ALL-CAPS. If I copy each of the localizable strings from the Settings' Root.strings files into the respective Localizable.strings files, the Preferences window strings still don't get localized.If anyone familiar with the subtleties of localization and Catalyst can offer suggestions for me to diagnose or fix these problems, let me know what to try next.Regards, Brian
2
0
1.5k
Aug ’19
Getting familiar with xcassets asset catalogs
I'm in the midst of moving all of my images into asset catalogs, adding size classes, and applying tags.I have two kudos's to share for any Apple engineers who might be reading: it's been really useful to work with multiple selected assets, thank you for allowing multiple selection; and, it's been really useful to drag a set of images into an asset catalog and have them associated with each other based on file name (e.g., .png, @2x.png, @2x~iPad.png).I started with single monolithic asset catalog, but then I realized that I will need multiple asset catalogs in order to separate out some images between Xcode targets (different apps), but not before I already started adding and configuring a ton of assets that now need to be separated out. So, I have two workflow questions:Is it possible to break out a set of assets, that are already in an asset catalog folder and configured with size classes and tags, into their own asset catalog file? If so, how? I tried dragging them out but that doesn't work.Is it possible to "name" image files appropriately for size classes, so that when I drag a set of images, they are associated with each other by size class? If so, what is the naming convention? I know this works for ~iPad, but I'm transitioning away from specifying iPad to specifying size regular.Thanks in advance for any tips on these.
4
1
4.7k
Jul ’15