ahmdyasser
(Ahmad Yasser)
February 10, 2023, 12:28am
1
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.
ksluder
(Kyle Sluder)
February 10, 2023, 12:57am
2
Is the source of SkeletonView available anywhere?
bbrk24
February 10, 2023, 1:05am
3
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
ahmdyasser
(Ahmad Yasser)
February 10, 2023, 1:07am
4
Yes it's a swift package and added as a dependency.
ksluder
(Kyle Sluder)
February 10, 2023, 1:08am
5
I meant, can you please provide a link to the source? I want to see whether it’s importing UIKit as @_implementationOnly
.
ahmdyasser
(Ahmad Yasser)
February 10, 2023, 1:10am
6
Yes sure, it's an open-source package
SkeletonView
ahmdyasser
(Ahmad Yasser)
February 10, 2023, 1:22am
7
No, every imported module is imported normally without @_exported