Chapter 3. Creating an iOS Swift App

With the release of Xcode 6 in 2014, it is possible to build Swift applications for iOS and OS X and submit them to the App Store for publication. This chapter will present both a single view application and a master-detail application, and use these to explain the concepts behind iOS applications as well as introduce classes in Swift.

This chapter will present the following topics:

  • How iOS applications are structured
  • Single view iOS applications
  • Creating classes in Swift
  • Protocols and enums in Swift
  • Using XCTest to test Swift code
  • Master-detail iOS applications
  • The AppDelegate and ViewController classes

Understanding iOS applications

An iOS application is a compiled executable, along with a set of supporting files in a bundle. The application bundle is packaged into an archive file for installing onto a device or uploading to the App Store.

Tip

Xcode can be used to run iOS applications in a simulator, but running an application on a device requires a developer signing key, which is included as part of the iOS developer program at https://developer.apple.com.

Most iOS applications to date have been written in Objective-C, a crossover between C and Smalltalk. With the advent of Swift, it is likely that many developers will move at least parts of their applications to Swift for performance and maintenance reasons. Although Objective-C is likely to be around for a while, it is clear that Swift is the future of iOS development, and probably OS X as well.

Applications contain a number of different types of files, which are used both at compile time and also at runtime. These files include:

  • The Info.plist file, which contains information about which languages the application is localized for, what the identity of the application is, and the configuration requirements, such as the supported interface types (iPad, iPhone, and Universal) and orientations (Portrait, Upside Down, Landscape Left, and Landscape Right)
  • Zero or more interface builder files with a .xib extension, which contain user interface screens (which supersedes the previous .nib files)
  • Zero or more image asset files with a .xcassets extension, which store groups of related icons at different sizes, such as the application icon or graphics for display on screen (which supersedes the previous .icns files)
  • Zero or more storyboard files with a .storyboard extension, which are used to coordinate between different screens in an application
  • One or more .swift files that contain application code
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset