Search code examples
iosswiftuikitfoundation

Why can I just use the types defined in the Foundation framework just by importing the UIKit framework?


Why can I just use the types defined in the Foundation framework just by importing the UIKit framework?

import UIKit

// String is a Type defined in Foundation framework
let foo: String = ""

I understand that the UIKit framework depends on the Foundation framework.

// Dependency
Application --> UIKit --> Foundation

Are there any compiler options that allow an application to use a dependent framework indirectly?

I would like to specify any such options when creating my own embedded framework.


Solution

  • I may need correcting on this, but my understanding of this is that there are not.

    Even though UIKit depends on Foundation, UIKit does not contain it. If that were the case, it would lead to immeasurable bloat as the majority of Frameworks use types defined in Foundation.

    If you want a Framework to be able to 'pass on' types and methods in a Framework it is dependant on, you'll either need to include the Framework it's dependent on and allow the application to access them directly, or alternatively you could add some method signatures and typedef declarations in your own Framework to bridge the gap, for want of a better expression.

    It's also worth looking at This article on the swift.org forums which may help you do what you need, although so far it looks as if what you're trying to do is not officially supported.