Xcode How To: Naming Your Tests

I noticed something that might be of interest to y’all.

At one point I asked my team if the preference was to name test files as MyFileTests or TestMyFile.

I’ve noticed that for test files that end with Tests you get this nice output in the Counterparts menu where the test and the implementation file are linked.

This only works if the test is named MyFileTests and there isn’t any deviation. (ex. MyFile and MyFileTests and not TestMyFile)

What does Xcode show?

Screenshot of Xcode counterparts menu showing tests when test file ends with the word Tests

Screenshot of Xcode counterparts showing test file and file name when test file name ends with the word Tests

Screenshot of Xcode counterparts menu not showing tests when the test file name is prefixed with the word Test

Xcode How To: Run Tests Without Running All Tests

TIL: if you are running the same test case over and over you can mash ⌃⌥⌘G and Xcode will rerun the last test case you just ran.

Importantly this will just run whatever you had run just before. So if it’s a whole test case, it runs that again. If it’s a single test it will run that again. If it’s multiple tests, it will run that again.

From a friend: It also preserves the run many times aspect. So if you're running 1000 times, you can keep hitting it to run 1000 more times.

You can also run “selected” tests with ⌃⌥⌘U so if you select some text, you can run the tests within that selection.

Where can I find these in the Menu bar?

These options all live in the Product menu under Perform Action labeled as Test and Test Again.

How did I find this?

The reason I stumbled upon this was because I was adding tests to a file that exists and it’s taking me a couple tries to get it all right. I want to be able to edit the setup steps and then run the XCTestCase again without running the entire Test Scheme or Test Plan. I looked into Xcode key bindings to see what was there and found this.

Hope it can help someone else!

How to fix WatchKit app WeatherKit issues

I made an iOS app that used WeatherKit. Everything was working as expected and recently I wanted to add an WatchOS component. Because I am adding the watch app to an existing iOS app, I added the target in Xcode and made sure to update the capabilities to the watch app so that it could use WeatherKit too.

Unfortunately I kept running into an auth error where when running the watch app, WeatherKit couldn’t created a jwt and therefore no weather data was making it to the app.

I then went to developer.apple.com and tried to add an identifier for my watch app but it wouldn’t let me. Saying the identifier was invalid. Argh!!! I was so confused.

I thought “maybe I need to wait a couple days for some process to complete”, but still no luck.

Finally I decided I’d make a fresh watchOS/iOS app and plug my weather framework into that, create a new identifier and everything would surely work. Right?!

Well then I get the exact same error in the developer portal! What the hell is going on.

Here is the important part: it turns out that in some cases Xcode automatically creates identifiers in the developer portal. You may see a bunch of identifiers that start with XC.

Then I realized that my watch kit app identifier was there the whole time! …if only the developer portal errors were clearer about why I couldn’t create a new identifier…

Anyways, then I clicked on my watchkitapp identifier, added the capability and the service for WeatherKit and voila, it worked!!!

tl;dr if you’re unable to create an identifier in developer.apple.com, check that the identifier wasn’t already automatically created for you. 🤷🏽‍♂️

Partial Solar Eclipse 2024

I live in South Carolina so I wasn’t in the path of totality, but I still wanted to see the eclipse. Unfortunately I forgot to get glasses, but I still wanted to see it. I was reading about when it would be happening and I learned that I could make a pinhole projector out of some boxes, tape, and a piece of paper.

pinhole project made of diaper boxes sitting in my driveway

projection of the eclipse from my pinhole projector.

shadows produced by a tree during the eclipse.

It's a curse to know how to make software

Over dramatic title, but there is some truth to it.

As a software developer I know how to make things. Maybe not super well, but I can get there. I also like to pay for software that others make.

The thing I run into is that I sometimes feel like I can make the thing and so I do. There are some benefits of this.

  1. I save some money
  2. I learn how to make a thing
  3. It’s fun to reverse engineer stuff

The problem with this is that I have a ton of tiny little projects that don’t work quite as well because I get bored with the fine tuning and polishing. And then I have something that works well enough, but not as well as the original thing I based my software on.

This whole thing reminds me of when people are doing home improvement projects and there is an option to pay someone to do it, but someone feels like they can do it themselves.

Maybe this isn’t a problem or a curse at all, just a way to spend time working on something.

Some sort of hawk at Middleton Place

These are from a little over a month ago, but I was able to sit here and film this bird for over 2 minutes. It was so cool to see the wind moving its feathers and how calm and focused it was (my words, I don’t know what it was thinking).

I’m so thankful to have moved somewhere that is warmer than where I used to live.

How to fix zsh completions

I was trying to add some zsh completions and I couldn’t figure out why they weren’t working. I had added them into a folder that I was running autoload on, but I still couldn’t get it to work.

I found this stackoverflow post and it saved me.

Here is what my .zshrc looks like now.

The code

autoload -Uz compinit && compinit

# enable case insensitive tab completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
fpath=(/usr/local/share/zsh-completions $fpath)
source $DOTFILES/zsh-completions/_arduino_cli

NOTE: I set up environment variables for important paths hence the $DOTFILES line.

So what is this doing?

I think the gist of this is autoload compint (I was already doing this) and then source your completion files (I was not doing this).

I’ll probably later write a nice loop for this if I end up with more completions.

Back to the beach.

My family and I recently took a trip to Missouri after having moved to South Carolina about six months ago.

It was nice to see family and friends.

It was also nice to have a reminder for why we moved here in the first place.

No matter where you go or what you do there will be trade-offs. When I go to the beach and see my daughter’s eyes light up, I know that I’m happy with the trade-offs we’ve made to get here.

My oldest daughter standing in the wake

A userscript to add links to headers in articles

I read a lot of things on the internet and sometimes I want to save my position for later. Many websites use HTML section heading tags to mark sections of their content. Many of these websites attach an id attribute which is nice because if you paste that id into the url like https://nickkaczmarek#some-id you can link to the spot in the website that contains that id.

Some websites go even further and provide an anchor to that section heading and it makes it really easy to just click that value and then if the page is reloaded you will stay at that spot. This website by Sarun Wongpatcharapakorn is a great example of a site that provides clickable links to parts of the article.

Unfortunately many websites either don’t have these id attributes (for instance my website 😬) or they do, but you can’t click on them. If you’re particularly pioneering you can inspect the web content, grab the id, and paste it in the address bar in your browser. As you can see that is a lot of work and also assumes you are even familiar with how to do that.

I have been doing the above for a long time and finally I decided I would try to make this better with some automation. So I wrote a userscript to do this for me.

There are many userscript extensions out there. I use one for safari called Userscripts and you can use this on a Mac and an iPhone. There are also Chrome and Firefox extensions with names like TamperMonkey, GreaseMonkey, etc. They all more or less work the same.

# The Code

It’s not perfect, but it has worked on a number of websites for me including wikipedia (where I want to use this most).

# What it looks like when it’s off:

screenshot of website without my userscript

# What it looks like when it’s on:

Screenshow of website with my userscript

How to use git to revert changes to individual files or foldersvidual

This is something I need to do often and often forget how to do it.

tl;dr: git checkout main <filename>


Like anything else this is nuanced and there are other ways to accomplish this as well as other arguments to revert to a point in time instead of just the tip of main.

Revert a commit

If you want to a revert a whole commit you can do git revert <hash>.

Revert a file or folder

But what if you want to revert one file or one folder to what is in your main branch?

You can do git checkout main <filename>.

An example repository where you have this structure:

├── main.swift
├── Service
│   ├── Service.swift
│   └── README.md
└── start-docker.sh

You could do git checkout main main.swift to undo main.swift to where it was on main.

Or you could do git checkout main Service to undo the whole directory to where it was on main.

Why would I want to do this?

The situation where I found this useful was that I had a long running branch and I wanted to merge part of the code into main. The problem was there were a handful of files that I did not want to merge to main.

I could have reverted the commits where they were made, but this branch had a lot of commits and I wasn’t sure exactly when these changes were made.

I also could have manually changed them back to what they were in main, but this was a better solution for my use case.

Maybe you’ll find it useful as well.