iOS 9 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics

iOS 9 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa BasicsReviews
Author: Matt Neuburg
Pub Date: 2015
ISBN: 978-1-491-93677-0
Pages: 604
Language: English
Format: PDF/EPUB
Size: 10 Mb


Move into iOS 9 development by getting a firm grasp of its fundamentals, including Xcode 7, the Cocoa Touch framework, and Apple’s Swift programming language. With this thoroughly updated guide, you’ll learn Swift’s object-oriented concepts, understand how to use Apple’s development tools, and discover how Cocoa provides the underlying functionality iOS apps need to have.

  • Explore Swift’s object-oriented concepts: variables and functions, scopes and namespaces, object types and instances
  • Become familiar with built-in Swift types such as numbers, strings, ranges, tuples, Optionals, arrays, and dictionaries
  • Learn how to declare, instantiate, and customize Swift object types—enums, structs, and classes
  • Discover powerful Swift features such as protocols and generics
  • Tour the lifecycle of an Xcode project from inception to App Store
  • Create app interfaces with nibs and the nib editor, Interface Builder
  • Understand Cocoa’s event-driven model and its major design patterns and features
  • Find out how Swift communicates with Cocoa’s C and Objective-C APIs

Changed behavior is terribly troublesome, and I have little advice to give you. Often the issue is one of sheer breakage, or breakage and repair. For example, code using UIProgressView’s progressImage property works in iOS 7, doesn’t work at all from iOS 7.1 through iOS 8.4, and works in iOS 9. You have no way of knowing this aside from trial and error, and working your way around it coherently is extremely tricky.

Less unpredictable but just as drastic, alert views are presented using UIAlertView in iOS 7 and before, but with UIAlertController in iOS 8 and later. Your simplest solution would be to keep using UIAlertView even in iOS 8 and later, but you cannot guarantee that this will always work, as UIAlertView is deprecated in iOS 9 and may eventually be dropped altogether — plus, you’re robbing yourself of the chance to use UIAlertController, which is a significantly better API. The situation with popovers is similar (UIPopoverController vs. UIPopoverPresentationController). In this way, improvements from one system to the next present the developer with a nasty paradox: they are desirable, but they make backward compatibility harder.

New in Xcode 7, however, the compiler will at least help you in one way that it never did before — by deliberately making it difficult for your code to use features not supported on the target system. Prior to Xcode 7, if you were to set the project’s Deployment Target to an earlier system, your code would compile and your app would run on that earlier system, even if it contained features that didn’t exist on that earlier system — and then your app would crash on that earlier system if any of those features were actually encountered. In Xcode 7, the compiler will prevent that situation from arising in the first place.
Thus, for example:

let arr = self.view.layoutGuides

The UIView layoutGuides property exists only on iOS 9.0 and later. Formerly, the compiler would permit that code to compile even if your deployment target was, say, iOS 8.0; realizing that that code must never actually run on iOS 8 was up to you. Now, however, the compiler will stop you with an error: “layoutGuides is only available on iOS 9.0 or newer.” You cannot proceed until you acknowledge to the compiler that this code is to run only on iOS 9 or later. And Xcode’s Fix-It feature will show you how to do that: