Weblog entries 2020

2020-07-16 Error in SwiftUI preview

Today, one SwiftUI Preview would not show anything. The Diagnostics button showed the following error:

    GenericHumanReadableError: unexpected error occurred
    noPreviewInfos(arch: "x86_64", sdkRoot: "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.6.sdk")

After a bit of fiddling, I found out the cause. This project had multiple targets. And the file was not a member of the currently selected target.

Edit 2021-01-15: the above solution was only temporary. Another attempt involved removing all unittests also temporarily "fixed" this problem. At the moment, this seems to be a very rare error and I have not been able to find a definitive cause or solution.

2020-05-27 Fixing a slow build in Xcode

If your Xcode project isn't compiling as fast as you expect, open the build settings of target that you're building. Add the following to the "Other Swift Flags" setting:

    -Xfrontend -warn-long-expression-type-checking=100

This makes the compiler emit warnings when it takes more than 100 ms to type-check an expression.

2020-03-05 Capping an array in Swift

Do you want to cap an array in Swift to a certain size? Here's how:

    var array = ["a", "b", "c", "d", "e"]
    array.replaceSubrange(3..., with: [])

The array now contains three items. It'll crash when instead of 3, you enter an index that's beyond the array count. If you wish to avoid that, do something like the following:

    array.replaceSubrange([0, array.count, 3].sorted()[1]..., with: [])

2016-05-26 Printing on a Kyocera FS2020D from OS X

Here's how you can install a Kyocera FS2020D printer on OS X.

First, download and install the driver: https://www.kyoceradocumentsolutions.co.uk/index/products/download_centre.false.driver.FS2020D._.EN.html#MAC This will cause an additional icon to appear in the System Properties app. It's labeled "Select PDL". You can ignore it.

If you have the hostname or IP address of the printer, great. If not, find out the IP address of the printer as follows. On the printer, press the menu button, then arrow right and arrow down. The display should say "status page". Press OK and a single status page is printed. It'll mention a couple of things, but most importantly its IP address.

On OS X, in System Preferences, go to Printers & Scanners, add a printer with the plus button, go to the second tab and fill in the IP address. Set protocol to Line Printer Daemon.

That should be all you have to do. If you wish, adjust the name, then click the Add button.

Happy printing.