Swift Framework Woes – Unresolved Identifier? No Member?

It’s the simple things that get us, isn’t it?

I was working on a simple little framework the other day, and I’d gotten things just how I wanted… or so I thought.

I was ready to test things out and import the framework into my real app.

import MyShinyNewFramework

Sweet! No build errors!

// attempt to use things defined in the framework

Not so sweet…

Use of unresolved identifier ‘…’

Value of type ‘…’ has no member ‘…’

I scrunched my forehead, puzzled, and immediately it came to me.

public public public all the things! Or at least, the things that others need to use from the framework. :]

Of course a framework’s usable API needs to be public, but I write far more code that doesn’t require thought of access control modifiers than code that does, so there’s always that initial head-scratching that happens when you’re to the point of testing and go, “WHAT?? Why is this not working??!”

Key Takeaway

Whenever you’re developing code (such as a framework) that’s intended to be used from the perspective of another Swift module, you need to include public before Types and functions that are intended to be “seen” and called from that other module. Otherwise, you’ll get those same fun compiler errors and join me in saying to yourself, “Doh! Yep… public… again.”