Reputation: 1450
A lot of tutorials on frameworks (AVFoundation, AudioToolBox, Social, MPMediaPlayer, iAd, etc) start by saying that it is must to link the respective frameworks (target settings ->build phases->link binary with libraries->add frameworks).
Most of the times I have found the import statement alone to be sufficient and my app works perfectly on real device and the simulator. For example, if I wish to play audio using MPMusicPlayer, "import MediaPlayer" works perfectly for me.
My question is, as long as the app works perfectly on simulator as well as the device, is it safe to omit such linking of frameworks (and using import statements instead)?
Upvotes: 3
Views: 471
Reputation: 7634
It's not necessary to link the framework if you import
it.
A long time ago, before Swift came along and we all used Objective-C, we had to link the frameworks with our app and have this line at the top of all of our files that needed this framework:
#import <SomeFramework/SomeFramework.h>
But then came the @import
statement. Now we only needed to write:
@import SomeFramework;
and the compiler would automatically link the framework and import it into the file. But we could still manually link libraries for compatibility (and since some libraries couldn't be @import
ed.)
Swift's import
statement functions the same as Objective-C's @import
, so you don't need to link the framework since it is automatically linked.
Upvotes: 9