2022-03-27

PreferenceKey Quirks

PreferenceKey has a few quirks that have tripped me up. One is the reduce(value:nextValue:) implementation. The other is that a PreferenceKey will not propagate upward past a View that has a preference(key:value:) set using the same PreferenceKey.

reduce(value:nextValue:)

I've found that PreferenceKey's reduce(value:nextValue) will be called several times, even if there are no other Views that have a preference() with the same PreferenceKey in the View tree. And sometimes nextValue() in those calls will return a nil value. Because of this, nextValue() should do more than just

One option is to reduce based on a timestamp:

PreferenceKey Propagation Blocked by preference(key:value:)

Another issue I've found is a PreferenceKey will not get passed up through the View tree past any parent View that uses the same PreferenceKey in a preference(key:value:)

The "Red" and "Green" buttons should generate "before" and "after" messages while the "Blue" and "Yellow" buttons should only create "after" messages and all buttons should change the color. But because of the issue the "Red" and "Green" buttons don't work as expected.

A way around this is to capture the preference before using it again:

Now the "Red" and "Green" buttons work as expected.

2021-12-13

Spotlight on macOS using a lot of CPU

If you are a developer on macOS and notice Spotlight consuming a lot of CPU the reason could be that Spotlight is indexing the Simulator and Platforms directories. When I ran lsof and checked the files that spotlight was accessing, it was reading files in ~/Library/Developer/CoreSimulator and /Applications/Xcode.app/Contents/Developer/Platforms. Adding those two directories to the Spotlight Privacy tab and then restarting your computer will prevent Spotlight from indexing them. Go to System Preferences > Spotlight > Privacy to add them.

2019-01-15

Restart Xcode Playground

If your playground ever crashes and/or gets stuck try switching the playground type in the File Inspector (right panel) to a different Platform and then back. This should restart the playground simulator.

2018-09-20

Simple Events in Swift

Events are useful when you need more than one delegate or event handler. Here is a simple class that can be used to manage events:




Use the uiSubscribe and uiUnsubscribe to have the Event class automatically run the event handler on the main DispatchQueue (for GUI related stuff). Here is an example of how to use them:

2018-09-18

UIColor Extension for RGBA Hex and HSLA

Here is an extension for UIColor that I've found useful when working with Photoshop and Web designers. It allows you to specify a UIColor in RGBA hex or HSLA.

2014-03-26

Label Sphere will be removed

I will be removing the Label Sphere from the Blogger Gadgets list on April 5th. This may break the Label Sphere on your blog. If you want to keep using the Label Sphere then read on.

If you have manually added the latest gadget using the url http://alexdioso.github.com/LabelSphere/LabelSphere.xml then you don't have to do anything.

If you have not manually added (or don't know) then you probably added the Label Sphere using the Gadgets list. To keep using the Label Sphere:

  1. Remove the current Label Sphere on your blog.
  2. Click on "Add a Gadget".
  3. In the "Add a Gadget" window that opens:
    1. In the left column, click "Add your own".
    2. Enter the url:  http://alexdioso.github.com/LabelSphere/LabelSphere.xml
    3. Click "Add by URL".

2012-04-21

Displaying user@host in tmux window titles

I use tmux a lot (having switched from GNU Screen) and frequently ssh to different hosts from different tmux windows. One thing that I find helpful is knowing which host I'm ssh'd to in each tmux window. Here is a little trick for your .bash_aliases (on every host you ssh to) which will display user@host in each tmux window title:
The first part sets the terminal's window title to user@host: /working/directory
\033]2;${USER}@${HOSTNAME}: ${PWD}\007
The second part set's the current tmux window title to user@host
\033k${USER}@${HOSTNAME}\033\\

PreferenceKey Quirks

PreferenceKey has a few quirks that have tripped me up. One is the reduce(value:nextValue:) implementation. The other is that a PreferenceKe...