Importing inner imported modules

When I import package like Kingfisher, and use its content in an extension, this won't require importing UIKit, only import Kingfisher will be enough.
Example.

import Kingfisher

extension UIImageView {
    func setImage(with urlString: String) {
        guard let url = URL.init(string: urlString) else { return }
        let resource = ImageResource(downloadURL: url, cacheKey: urlString)
        var kf = self.kf
        kf.indicatorType = .activity
        self.kf.setImage(with: resource)
    }
}

This also works for Apple frameworks, for example when I import UIKit, I don't have to import Foundation. But when I import something like SkeletonView package (and it imports UIKit too), but this one produces an error that you must import UIKit.

I don't understand the logic here if anyone can explain.

Is the source of SkeletonView available anywhere?

I believe this depends on how the package is written.

If the package is written in Objective-C, and it imports UIKit, you only need to import that package and not UIKit.

If the package is written in Swift, and contains the line @_exported import UIKit, you only need to import that package and not UIKit.

If the package is written in Swift, and it imports UIKit without the @_exported attribute, importing that package is not sufficient to expose UIKit.

2 Likes

Yes it's a swift package and added as a dependency.

I meant, can you please provide a link to the source? I want to see whether it’s importing UIKit as @_implementationOnly.

Yes sure, it's an open-source package
SkeletonView

No, every imported module is imported normally without @_exported