Swift 2.0 Basics Summary

2015-07-21  本文已影响0人  碧波浮沉

Chapters: The Basics - Properties

Excerpt From: Apple Inc. “The Swift Programming Language (Swift 2 Prerelease).” iBooks. https://itun.es/us/k5SW7.l

The Basics

Fundamental types: Bool, Int, Float, Double, String, Array, Set, Dictionary

Advanced types: tuples, optionals

Basic Operators

Strings and Characters

Collection Types

Control Flow

Functions

Closures

Enumerations

  1. When can one use the shorthand dot syntax?

“Once a variable is declared as a enum class object, you can set it to a different value using a shorter dot syntax. This makes for highly readable code when working with explicitly-typed enumeration values.”

  1. What are associated values?

“You can define Swift enumerations to store associated values of any given type, and the value types can be different for each member of the enumeration if needed. ”

    enum Barcode {
      case UPCA(Int, Int, Int, Int)
      case QRCode(String)
    }
  1. What are raw values?

“As an alternative to associated values, enumeration members can come prepopulated with default values (called raw values), which are all of the same type.”

    enum ASCIIControlCharacter : Character {
      case Tab = "\t"
      case LineFeed = "\n"
      case CarriageReturn = "\r"
    }

Classes and structures

Properties

上一篇 下一篇

猜你喜欢

热点阅读