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

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

Language: English

Pages: 582

ISBN: 1491908904

Format: PDF / Kindle (mobi) / ePub


Move into iOS development by getting a firm grasp of its fundamentals, including the Xcode IDE, the Cocoa Touch framework, and Swift—Apple’s new 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

Once you master the fundamentals, you’ll be ready to tackle the details of iOS app development with author Matt Neuburg’s companion guide, Programming iOS 8.

Functional Programming in Swift

Processing: A Programming Handbook for Visual Designers and Artists

Head First C

iOS 5 Recipes: A Problem-Solution Approach

 

 

 

 

 

 

 

 

 

 

 

 

 

putting an exclamation mark or a question mark after the function call (that is, after the closing parenthesis). This is really no different from what we did in the preceding code with window?, except that instead of a property that returns an Optional, this is a function call that returns an Optional. For example: class Dog { var noise : String? = nil func speak() -> String? { return self.noise } } let d = Dog() let bigname = d.speak()?.uppercaseString After that, don’t forget, bigname is not a

returns an Optional because the conversion can fail. If s is "howdy", it isn’t a number. Thus the type returned cannot be an Int, because there is no Int that can be taken to mean, “I didn’t find any Int.” Returning an Optional solves the problem neatly: nil means “I didn’t find any Int,” and otherwise the actual Int result is sitting there wrapped up in the Optional. Swift is cleverer than Objective-C in this regard. If a reference is an object, ObjectiveC can return nil to report failure; but

static let hostile = "go away" static var ambivalent : String = { return self.friendly + " but " + self.hostile // compile error }() } Methods A method is a function — one that happens to be declared at the top level of an object type declaration. That means that everything said about functions in Chapter 2 applies. 124 | Chapter 4: Object Types By default, a method is an instance method. This means that it can be accessed only through an instance. Within the body of an instance method,

tialized in all of its initializers: class Dog { var name : String var license : Int init(name:String, license:Int) { self.name = name self.license = license } } let d = Dog(name:"Rover", license:42) This class is similar to the previous example, but it also has two convenience initializers. The caller doesn’t have to supply any parameters, because a convenience initializer with no parameters calls through a chain of convenience initializers ending with a designated initializer: class Dog { var

name : String var license : Int init(name:String, license:Int) { self.name = name self.license = license } convenience init(license:Int) { self.init(name:"Fido", license:license) } convenience init() { Classes | 153 self.init(license:1) } } let d = Dog() Note that the rules about what else an initializer can say and when it can say it, as I described them earlier in this chapter, are still in force. A designated initializer cannot, except in order to initialize a property, say self until

Download sample

Download

About admin