Post

Replies

Boosts

Views

Activity

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
Dec ’21
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
822
Aug ’21