A Gotcha When Testing Swift Frameworks with Xcode 6

After spending most of the summer delving into what Swift can and can’t do as a functional programming language, I’ve turned my attention to writing real library code in Swift. I do have a day job, after all, and while thinking about Magical Future Swift is a fun exercise, I still need to learn how to do the basic everyday things. Which is where I was tripped up by the default framework test settings.

The issue occurred when I created a new Cocoa framework project, in Swift. By default these come with tests, so you’d be forgiven for thinking that the tests just run when you type Cmd-U, as they would for an app. You would be wrong, however. Most of the “Product” menu is disabled and gives that heart-sinking “you can’t do what you think you can do” sound when you try the shortcuts.

What happens is that by default, the test bundle is not added to the test configuration of the framework’s build scheme. Here’s how you reenable it. Say you named your framework “test” (I’m creative like that). Select it and then select “Edit Scheme…”:


Then go to “Test” and hit the + in the lower left-hand corner of the detail view:


Select your test bundle (my clever naming pays off dividends…):


Make any modifications you want — in this case, let’s add a location for the tests to run against, and click “Close”:


Now all your testing shortcuts should be enabled and working (your running shortcuts still won’t be, since a framework can’t be run on its own).

Happy testing!


Now read this

Error Handling in Swift: Might and Magic—Part II

In my previous post, I showed that defining a map method on the Result enum allows chaining of a series of transformations to a result without caring whether the result was a success or a failure until the value was needed for output. I... Continue →