My iOS app plays sounds with AVPlayer
. To do this I had to type following on the top of a class:
import AVFoundation
I came from Objective-C background, so I went to Xcode project's General tab and added AVFoundation
there by clicking on plus button under the Linked frameworks and libraries. Yellow toolbox appeared in my project. Do I have to do this?
I tried to remove it from the project — both from the sidebar and in Xcode preferences, my app still works and sounds are playing. So does import
handling everything for you?
Frameworks are structured directories containing code, sub-directories, shared libraries, and other support files. Whereas libraries only has executable code. Assets cannot be carried along with a library. In contrast with Frameworks that we can put everything into a single package.
Libraries provide developers with predefined functions and classes to make their work easier and boost the development process. Framework, on the other hand, is like the foundation upon which developers build applications for specific platforms.
A library is simply a collection of files, for use as a dependency by other Swift code. An executable is a package that can be run, such a web server. Dependencies are other Swift Packages you want to use code from, within your package.
Yes, import
in Swift is basically the same as @import
in Objective-C (as opposed to #import <…>
), which import modules.
This new feature (modules) was introduced recently (1-2 years ago?) and does import the framework for you without the need to explicitly link you app with it: when using modules (@import
in ObjC, import
in Swift), the compiler will see the module name and link your app with the framework implicitly and automagically for you.
So that's a new feature we didn't have back in the day when #import
were the only option and we had to manually add system frameworks ourselves.
(Note that modules were only available for Apple's frameworks until iOS8 arrived. But now that you can build your own dynamic frameworks when building for iOS8, they are available for third-party frameworks as well, as long as they have a module.map
)
If you're interested, you can read more in the Clang documentation itself. Various blog posts also talk about the subject (e.g. first Google result is this blog post)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With