Swift Pocket Reference: Programming for iOS and OS X

Swift Pocket Reference: Programming for iOS and OS X

Language: English

Pages: 236

ISBN: 1491940077

Format: PDF / Kindle (mobi) / ePub

Swift Pocket Reference: Programming for iOS and OS X

Language: English

Pages: 236

ISBN: 1491940077

Format: PDF / Kindle (mobi) / ePub


Get quick answers for developing and debugging applications with Swift, Apple’s multi-paradigm programming language. Updated to cover the latest features in Swift 2.0, this pocket reference is the perfect on-the-job tool for learning Swift’s modern language features, including type safety, generics, type inference, closures, tuples, automatic memory management, and support for Unicode.

Designed to work with Cocoa and Cocoa Touch, Swift can be used in tandem with Objective-C, and either language can call APIs implemented in the other. Swift is still evolving, but Apple clearly sees it as the future language of choice for iOS and OS X software development.

Topics include:

  • Supported data types, such as strings, arrays, array slices, sets, and dictionaries
  • Program flow: loops, conditional execution, and error handling
  • Classes, structures, enumerations, and functions
  • Protocols, extensions, and generics
  • Memory management
  • Closures: similar to blocks in Objective-C and lambdas in C#
  • Optionals: values that can explicitly have no value
  • Operators, operator overloading, and custom operators
  • Access control: restricting access to types, methods, and properties
  • Ranges, intervals, and strides
  • A full list of built-in global functions and their parameter requirements

iPhone Cool Projects

C++ Primer (5th Edition)

Beginning iOS Cloud and Database Development: Build Data-Driven Cloud Apps for iOS

Mastering Algorithms with C

The Swift Programming Language

Getting Started with UDK

 

 

 

 

 

 

 

 

 

 

access the two values like this: let limits = getRange() for i in limits.lower...limits.upper { … } The optional tuple return type For cases in which a tuple is the return type of a function, you might want to indicate the tuple has no value. Extending the previous getRange() example, it might be the case that no valid range exists, and thus there is nothing to return. This can be managed by using an optional return type for the tuple, which you indicate by following the parentheses around the

value. Optional chaining is a facility by which you can query an optional, or something that depends on an optional having a value, without specifically having to test the optional first. You can use optional chaining when accessing class, structure, or enumeration properties, methods, or subscripts using dot-syntax. Consider this simple example of two classes, in which class A contains an optional reference to an instance of class B: class A { var otherClass: B? } class B { var someProperty:

displays alongside it in the results sidebar. Below the existing text, type the following: for var i=0; i<10; i++ { print (i) } The results sidebar now displays the text “(10 times)” to confirm the number of executions of the loop. If you hover the pointer over the entries in the results sidebar (Figure 4), you’ll see two symbols. The eye-like symbol provides a Quick Look view of the value (this includes viewers for complex data such as strings, arrays, dictionaries, images, views, URLs, and

SetAlgebraType protocol for types whose RawValue is a Bit​Wi⁠se​Op⁠era⁠tions​Type. See “Option Sets”. OutputStreamType Conforming types can be a target of a text stream. String adopts this protocol, meaning you can print() to a string. RandomAccessIndexType Conforming types are indexes that can be offset by arbitrary amounts in constant time. This includes all of the integer types. RangeReplaceable CollectionType Conforming types are collections that support replacement of an arbitrary range of

standard library are implemented as generics. For example, the Array type and the Dictionary type are generic collections that can store any type of data. In Swift, you can write generic code in a number of ways, including generic functions, generic types, and generic protocols. Generic Functions To see a classic example of where generics are useful, consider the Swift standard library function swap, which is defined as follows: func swap(inout a: T, inout b: T) From this function

Download sample

Download