Imports in Swift

July 20, 2014

One of greatest features of convenience that Apple released in the Swift programming language was deleting the necessity to import user created files.

The days of imports looking like this:

#import <UIKit/UIKit.h>
#import "GameBoardViewController.h"
#import "AppDelegate.h"
#import "BGCurrentUserController.h"
#import "BoardThemeModel.h"
#import <FacebookSDK/FacebookSDK.h>
#import "FBGame.h"
#import "GameManager.h"
#import "GameListViewController.h"
#import "GridCollectionViewLayout.h"
#import "NSString+XQueryComponents.h"
#import <Parse/Parse.h>
#import "PhraseCell.h"
#import "PushNotificationUtility.h"
#import "UIAlertViewHelper.h"
#import "UIDeviceMacros.h"
#import "StaticVariables.h"
#import "FBPhrase.h"
#import "GameBoardController.h"

…are over for native iOS developers.

Instead, this is what it might look like in Swift:

import UIKit

In addition, you don’t have to import System frameworks (i.e. CoreData, UIKit) manually from your build phases menu. Although, this feature has been around since Xcode 5 at least, but it is still really nice! For example, more than half of the following includes are not necessary:

frameworks xcode

Don’t do this! (anymore)

Another nice thing I enjoy about Xcode 6 and Swift is that the vast majority of Objective-C libraries and frameworks work just as well in Swift as they do in Objective-C. The time saver in all of that is that autocomplete converts Obj-C function declarations into a clean Swift format, even if they used blocks or something out of the ordinary.

Bridging headers seem kinda weird, but really they are not complicated at all. Also, with the autocomplete features mentioned above, you won’t even notice there are Objective-C classes in your project. Check out the docs on Using Swift and Obj-C in the same project.

Anyway, I could go on about the pros of these here new innovations, but check em out for yourself or wait until the Fall when they should all be released with iOS 8. Thanks for the read!

Tweet submit to reddit

Recent Posts

  • Moving From iOS To Server-Side Swift
  • The Default Memberwise Initializers Headache
  • Types of Swift Error Handling
  • My NSHipster Reader Submission
  • Top 9 Storyboard Mistakes in Xcode