Swift: Firebase 3 – How to Load Messages (Ep 9)

my review point is 9/10

firebase 에 관해 쉽게 접근할수 었었다.

https://youtu.be/cw0gLZHJOiE?t=2m   view controller를 아래로 내려가게 하면서 닫고 새로운 view controller가 옆에서 나오게 하는 작업 ( dismissViewControllerAnimated )

https://youtu.be/cw0gLZHJOiE?t=12m15s   xcode console에서 obj 값을 출력 ( po obj이름 )

https://youtu.be/cw0gLZHJOiE?t=12m37s   FIRAuth를 이용해서 uid를 구하는 방법 , timestamp 만드는 예시 ( FIRAuth.auth().currentUser.uid , NSDate().timeIntervalSince1970 )

https://youtu.be/cw0gLZHJOiE?t=17m30s   firebase database에서 데이터 가져오기

https://youtu.be/cw0gLZHJOiE?t=20m17s   dictionary로 되어있는 정보를 이용 obj를 만드는 쉬운 방법 ( setValuesForKeysWithDictionary ) 

https://youtu.be/cw0gLZHJOiE?t=22m31s   firebase작업은 다른 background thread에서 작동한다. main queue에 update하는 경우 ( dispatch_async , dispatch_get_main_queue  )

Swift type properties – Cosmin Mircea – Medium

All about Properties in swift – Abhimuralidharan – Medium

Methods

Methods are functions that are associated with a particular type. Classes, structures, and enumerations can all define instance methods, which encapsulate specific tasks and functionality for working with an instance of a given type. Classes, structures, and enumerations can also define type methods, which are associated with the type itself.

Instance Methods

Instance methods are functions that belong to instances of a particular class, structure, or enumeration. They support the functionality of those instances, either by providing ways to access and modify instance properties, or by providing functionality related to the instance’s purpose. Instance methods have exactly the same syntax as functions, as described in Functions.

You write an instance method within the opening and closing braces of the type it belongs to. An instance method has implicit access to all other instance methods and properties of that type. An instance method can be called only on a specific instance of the type it belongs to. It cannot be called in isolation without an existing instance.

Here’s an example that defines a simple Counter class, which can be used to count the number of times an action occurs:

class Counter {
   var count = 0
   func increment() {
       count += 1
   }

//  “amount” is parameter name
   func increment(by amount: Int) {
       count += amount
   }
   func reset() {
       count = 0
   }
}

The Counter class defines three instance methods:

let counter = Counter()
// the initial counter value is 0
counter.increment()
// the counter’s value is now 1

// by is argument label
counter.increment(by: 5)
// the counter’s value is now 6
counter.reset()
// the counter’s value is now 0

The self Property

Every instance of a type has an implicit property called self, which is exactly equivalent to the instance itself. You use the self property to refer to the current instance within its own instance methods.

The increment() method in the example above could have been written like this:

func increment() {
   self.count += 1
}

In practice, you don’t need to write self in your code very often. If you don’t explicitly write self, Swift assumes that you are referring to a property or method of the current instance whenever you use a known property or method name within a method. This assumption is demonstrated by the use of count (rather than self.count) inside the three instance methods for Counter.

The main exception to this rule occurs when a parameter name for an instance method has the same name as a property of that instance. In this situation, the parameter name takes precedence, and it becomes necessary to refer to the property in a more qualified way. You use the self property to distinguish between the parameter name and the property name.

Here, self disambiguates between a method parameter called x and an instance property that is also called x:

struct Point {
   var x = 0.0, y = 0.0
   func isToTheRightOf(x: Double) -> Bool {
       return self.x > x
   }
}
let somePoint = Point(x: 4.0, y: 5.0)
if somePoint.isToTheRightOf(x: 1.0) {
   print(“This point is to the right of the line where x == 1.0”)
}
// Prints “This point is to the right of the line where x == 1.0”

(참고 https://medium.com/@andrea.prearo/reference-and-value-types-in-swift-dad40ea76226)

(참고 tumblr #swift  #var  #let  #reference  #value  #type  #mutable  #immutable  #immutablity  #variable )

Modifying Value Types from Within Instance Methods

Structures and enumerations are value types. By default, the properties of a value type cannot be modified from within its instance methods.

However, if you need to modify the properties of your structure or enumeration within a particular method, you can opt in to mutating behavior for that method. The method can then mutate (that is, change) its properties from within the method, and any changes that it makes are written back to the original structure when the method ends. The method can also assign a completely new instance to its implicit self property, and this new instance will replace the existing one when the method ends.

You can opt in to this behavior by placing the mutating keyword before the func keyword for that method:

struct Point {
   var x = 0.0, y = 0.0
   mutating func moveBy(x deltaX: Double, y deltaY: Double) {
       x += deltaX
       y += deltaY
   }
}
var somePoint = Point(x: 1.0, y: 1.0)
somePoint.moveBy(x: 2.0, y: 3.0)
print(“The point is now at ((somePoint.x), (somePoint.y))”)
// Prints “The point is now at (3.0, 4.0)”

Note that you cannot call a mutating method on a constant of structure type, because its properties cannot be changed, even if they are variable properties, as described in Stored Properties of Constant Structure Instances:

let fixedPoint = Point(x: 3.0, y: 3.0)
fixedPoint.moveBy(x: 2.0, y: 3.0)
// this will report an error

Assigning to self Within a Mutating Method

Mutating methods can assign an entirely new instance to the implicit self property. The Point example shown above could have been written in the following way instead:

struct Point {
   var x = 0.0, y = 0.0
   mutating func moveBy(x deltaX: Double, y deltaY: Double) {
       self = Point(x: x + deltaX, y: y + deltaY)
   }
}

Mutating methods for enumerations can set the implicit self parameter to be a different case from the same enumeration:

enum TriStateSwitch {
   case off, low, high
   mutating func next() {
       switch self {
       case .off:
           self = .low
       case .low:
           self = .high
       case .high:
           self = .off
       }
   }
}
var ovenLight = TriStateSwitch.low
ovenLight.next()
// ovenLight is now equal to .high
ovenLight.next()
// ovenLight is now equal to .off

Type Methods

You can also define methods that are called on the type itself. These kinds of methods are called type methods. You indicate type methods by writing the static keyword before the method’s func keyword. Classes may also use the class keyword to allow subclasses to override the superclass’s implementation of that method. (static 을 사용하여 type method를 만드는데 단 class의 경우 subclass에서 override를 해야 하는 경우 static대신 class를 사용한다는 설명)

NOTE

In Swift, you can define type-level methods for all classes, structures, and enumerations. Each type method is explicitly scoped to the type it supports.

Type methods are called with dot syntax, like instance methods. However, you call type methods on the type, not on an instance of that type. Here’s how you call a type method on a class called SomeClass(클래스이름에 dot notation을 사용한다는 뜻):

class SomeClass {
   class func someTypeMethod() {
       // type method implementation goes here
   }
}
SomeClass.someTypeMethod()

Within the body of a type method, the implicit self property refers to the type itself, rather than an instance of that type. This means that you can use self to disambiguate between type properties and type method parameters, just as you do for instance properties and instance method parameters.

More generally, any unqualified method and property names that you use within the body of a type method will refer to other type-level methods and properties. A type method can call another type method with the other method’s name, without needing to prefix it with the type name. Similarly, type methods on structures and enumerations can access type properties by using the type property’s name without a type name prefix.

(일반적으로는 self를 앞에 붙이지 않고 같은 type내의 method, property에 접근 가능하다는 이야기)

성취된 level을 type내에서 공유하면서도 각개인의 level을 유지관리하는 코드 예시

struct LevelTracker {
   static var highestUnlockedLevel = 1
   var currentLevel = 1
   
   static func unlock(_ level: Int) {
       if level > highestUnlockedLevel { highestUnlockedLevel = level }
   }
   
   static func isUnlocked(_ level: Int) -> Bool {
       return level <= highestUnlockedLevel
   }
   
   @discardableResult
   mutating func advance(to level: Int) -> Bool {
       if LevelTracker.isUnlocked(level) {
           currentLevel = level
           return true
       } else {
           return false
       }
   }
}

class Player {
   var tracker = LevelTracker()
   let playerName: String
   func complete(level: Int) {
       LevelTracker.unlock(level + 1)
       tracker.advance(to: level + 1)
   }
   init(name: String) {
       playerName = name
   }
}

var player = Player(name: “Argyrios”)
player.complete(level: 1)
print(“highest unlocked level is now (LevelTracker.highestUnlockedLevel)”)
// Prints “highest unlocked level is now 2”

player = Player(name: “Beto”)
if player.tracker.advance(to: 6) {
   print(“player is now on level 6”)
} else {
   print(“level 6 has not yet been unlocked”)
}
// Prints “level 6 has not yet been unlocked”

Properties

Properties associate values with a particular class, structure, or enumeration. Stored properties store constant and variable values as part of an instance, whereas computed properties calculate (rather than store) a value. Computed properties are provided by classes, structures, and enumerations. Stored properties are provided only by classes and structures.

Stored and computed properties are usually associated with instances of a particular type. However, properties can also be associated with the type itself. Such properties are known as type properties.

In addition, you can define property observers to monitor changes in a property’s value, which you can respond to with custom actions. Property observers can be added to stored properties you define yourself, and also to properties that a subclass inherits from its superclass.

Stored Properties

Stored properties can be either variable stored properties (introduced by the varkeyword) or constant stored properties (introduced by the let keyword).

You can provide a default value for a stored property as part of its definition, as described in Default Property Values. You can also set and modify the initial value for a stored property during initialization. This is true even for constant stored properties, as described in Assigning Constant Properties During Initialization.

struct FixedLengthRange {
   var firstValue: Int
   let length: Int
}
var rangeOfThreeItems = FixedLengthRange(firstValue: 0, length: 3)
// the range represents integer values 0, 1, and 2
rangeOfThreeItems.firstValue = 6
// the range now represents integer values 6, 7, and 8

let rangeOfFourItems = FixedLengthRange(firstValue: 0, length: 4)
// this range represents integer values 0, 1, 2, and 3
rangeOfFourItems.firstValue = 6
// this will report an error, even though firstValue is a variable property

This behavior is due to structures being value types. When an instance of a value type is marked as a constant, so are all of its properties.

The same is not true for classes, which are reference types. If you assign an instance of a reference type to a constant, you can still change that instance’s variable properties.

Stored Properties of Constant Structure Instances

If you create an instance of a structure and assign that instance to a constant, you cannot modify the instance’s properties, even if they were declared as variable properties:

let rangeOfFourItems = FixedLengthRange(firstValue: 0, length: 4)
// this range represents integer values 0, 1, 2, and 3
rangeOfFourItems.firstValue = 6
// this will report an error, even though firstValue is a variable property

This behavior is due to structures being value types. When an instance of a value type is marked as a constant, so are all of its properties.

The same is not true for classes, which are reference types. If you assign an instance of a reference type to a constant, you can still change that instance’s variable properties.

Lazy Stored Properties

A lazy stored property is a property whose initial value is not calculated until the first time it is used. You indicate a lazy stored property by writing the lazy modifier before its declaration.

NOTE

You must always declare a lazy property as a variable (with the var keyword), because its initial value might not be retrieved until after instance initialization completes. Constant properties must always have a value before initialization completes, and therefore cannot be declared as lazy.

class DataImporter {
   /*
    DataImporter is a class to import data from an external file.
    The class is assumed to take a nontrivial amount of time to initialize.
    */
   var filename = “data.txt”
   // the DataImporter class would provide data importing functionality here
}
class DataManager {
   lazy var importer = DataImporter()
   var data = [String]()
   // the DataManager class would provide data management functionality here
}
let manager = DataManager()
manager.data.append(“Some data”)
manager.data.append(“Some more data”)
// the DataImporter instance for the importer property has not yet been created

Because it is marked with the lazy modifier, the DataImporter instance for the importer property is only created when the importer property is first accessed, such as when its filename property is queried:

print(manager.importer.filename)
// the DataImporter instance for the importer property has now been created
// Prints “data.txt”

NOTE

If a property marked with the lazy modifier is accessed by multiple threads simultaneously and the property has not yet been initialized, there is no guarantee that the property will be initialized only once.

Computed Properties

getter and an optional setter to retrieve and set other properties and values indirectly.

struct Point {
   var x = 0.0, y = 0.0
}
struct Size {
   var width = 0.0, height = 0.0
}
struct Rect {
   var origin = Point()
   var size = Size()
   var center: Point {
       get {
           let centerX = origin.x + (size.width / 2)
           let centerY = origin.y + (size.height / 2)
           return Point(x: centerX, y: centerY)
       }
       set(newCenter) {
           origin.x = newCenter.x – (size.width / 2)
           origin.y = newCenter.y – (size.height / 2)
       }
   }
}
var square = Rect(origin: Point(x: 0.0, y: 0.0),
                 size: Size(width: 10.0, height: 10.0))
let initialSquareCenter = square.center
square.center = Point(x: 15.0, y: 15.0)
print(“square.origin is now at ((square.origin.x), (square.origin.y))”)
// Prints “square.origin is now at (10.0, 10.0)”

Shorthand Setter Declaration

If a computed property’s setter does not define a name for the new value to be set, a default name of newValueis used. 

struct AlternativeRect {
   var origin = Point()
   var size = Size()
   var center: Point {
       get {
           let centerX = origin.x + (size.width / 2)
           let centerY = origin.y + (size.height / 2)
           return Point(x: centerX, y: centerY)
       }

       // set(사용될변수이름) 

      //  이런 형태이나 아래와 같이 축약형으로사용 가능 newValue는 swift가          //  제공하는 기본 변수이름
       set {
           origin.x = newValue.x – (size.width / 2)
           origin.y = newValue.y – (size.height / 2)
       }
   }
}

Read-Only Computed Properties

A computed property with a getter but no setter is known as a read-only computed property. A read-only computed property always returns a value, and can be accessed through dot syntax, but cannot be set to a different value.

NOTE

You must declare computed properties—including read-only computed properties—as variable properties with the var keyword, because their value is not fixed. The let keyword is only used for constant properties, to indicate that their values cannot be changed once they are set as part of instance initialization.

struct Cuboid {
   var width = 0.0, height = 0.0, depth = 0.0
   var volume: Double {
       return width * height * depth
   }
}
let fourByFiveByTwo = Cuboid(width: 4.0, height: 5.0, depth: 2.0)
print(“the volume of fourByFiveByTwo is (fourByFiveByTwo.volume)”)
// Prints “the volume of fourByFiveByTwo is 40.0”

Property Observers

Property observers are called every time a property’s value is set, even if the new value is the same as the property’s current value.

You can add property observers to any stored properties you define, except for lazy stored properties. You can also add property observers to any inherited property (whether stored or computed) by overriding the property within a subclass. You don’t need to define property observers for nonoverridden computed properties, because you can observe and respond to changes to their value in the computed property’s setter. Property overriding is described in Overriding.

You have the option to define either or both of these observers on a property:

  • willSet is called just before the value is stored.
  • didSet is called immediately after the new value is stored.

If you implement a willSet observer, it’s passed the new property value as a constant parameter. You can specify a name for this parameter as part of your willSet implementation. If you don’t write the parameter name and parentheses within your implementation, the parameter is made available with a default parameter name of newValue.

Similarly, if you implement a didSet observer, it’s passed a constant parameter containing the old property value. You can name the parameter or use the default parameter name of oldValue. If you assign a value to a property within its own didSet observer, the new value that you assign replaces the one that was just set.

NOTE

The willSet and didSet observers of superclass properties are called when a property is set in a subclass initializer, after the superclass initializer has been called. They are not called while a class is setting its own properties, before the superclass initializer has been called.

class StepCounter {
   var totalSteps: Int = 0 {
       willSet(newTotalSteps) {
           print(“About to set totalSteps to (newTotalSteps)”)
       }
       didSet {
           if totalSteps > oldValue  {
               print(“Added (totalSteps – oldValue) steps”)
           }
       }
   }
}
let stepCounter = StepCounter()
stepCounter.totalSteps = 200
// About to set totalSteps to 200
// Added 200 steps
stepCounter.totalSteps = 360
// About to set totalSteps to 360
// Added 160 steps
stepCounter.totalSteps = 896
// About to set totalSteps to 896
// Added 536 steps

NOTE

If you pass a property that has observers to a function as an in-out parameter, the willSet and didSet observers are always called. This is because of the copy-in copy-out memory model for in-out parameters: The value is always written back to the property at the end of the function. For a detailed discussion of the behavior of in-out parameters, see In-Out Parameters.

Global and Local Variables

The capabilities described above for computing and observing properties are also available to global variables and local variables. Global variables are variables that are defined outside of any function, method, closure, or type context. Local variables are variables that are defined within a function, method, or closure context.

The global and local variables you have encountered in previous chapters have all been stored variables. Stored variables, like stored properties, provide storage for a value of a certain type and allow that value to be set and retrieved.

However, you can also define computed variables and define observers for stored variables, in either a global or local scope. Computed variables calculate their value, rather than storing it, and they are written in the same way as computed properties.

NOTE

Global constants and variables are always computed lazily, in a similar manner to Lazy Stored Properties. Unlike lazy stored properties, global constants and variables do not need to be marked with the lazy modifier.

Local constants and variables are never computed lazily.

Type Properties

Instance properties are properties that belong to an instance of a particular type. 

You can also define properties that belong to the type itself, not to any one instance of that type. There will only ever be one copy of these properties.

Type properties are useful for defining values that are universal to all instances of a particular type, such as a constant property that all instances can use (like a static constant in C), or a variable property that stores a value that is global to all instances of that type (like a static variable in C).

Stored type properties can be variables or constants. Computed type properties are always declared as variable properties, in the same way as computed instance properties.

NOTE

Unlike stored instance properties, you must always give stored type properties a default value. This is because the type itself does not have an initializer that can assign a value to a stored type property at initialization time.

Stored type properties are lazily initialized on their first access. They are guaranteed to be initialized only once, even when accessed by multiple threads simultaneously, and they do not need to be marked with the lazy modifier.

Type Property Syntax

type properties are written as part of the type’s definition, within the type’s outer curly braces, and each type property is explicitly scoped to the type it supports.

You define type properties with the static keyword. For computed type properties for class types, you can use the class keyword instead to allow subclasses to override the superclass’s implementation. The example below shows the syntax for stored and computed type properties:

struct SomeStructure {
   static var storedTypeProperty = “Some value.”
   static var computedTypeProperty: Int {
       return 1
   }
}
enum SomeEnumeration {
   static var storedTypeProperty = “Some value.”
   static var computedTypeProperty: Int {
       return 6
   }
}
class SomeClass {
   static var storedTypeProperty = “Some value.”
   static var computedTypeProperty: Int {
       return 27
   }
   class var overrideableComputedTypeProperty: Int {
       return 107
   }
}

NOTE

The computed type property examples above are for read-only computed type properties, but you can also define read-write computed type properties with the same syntax as for computed instance properties.

Querying and Setting Type Properties

(type property는 클래스에 존재하는 상수,변수이며 이는 클래스이름을 통해 공유된다.)

Type properties are queried and set with dot syntax, just like instance properties. However, type properties are queried and set on the type, not on an instance of that type. For example:

print(SomeStructure.storedTypeProperty)
// Prints “Some value.”
SomeStructure.storedTypeProperty = “Another value.”
print(SomeStructure.storedTypeProperty)
// Prints “Another value.”
print(SomeEnumeration.computedTypeProperty)
// Prints “6”
print(SomeClass.computedTypeProperty)
// Prints “27”

struct AudioChannel {
   static let thresholdLevel = 10
   static var maxInputLevelForAllChannels = 0
   var currentLevel: Int = 0 {
       didSet {
           if currentLevel > AudioChannel.thresholdLevel {
               // cap the new audio level to the threshold level
               currentLevel = AudioChannel.thresholdLevel
           }
           if currentLevel > AudioChannel.maxInputLevelForAllChannels {
               // store this as the new overall maximum input level
               AudioChannel.maxInputLevelForAllChannels = currentLevel
           }
       }
   }
}

var leftChannel = AudioChannel()
var rightChannel = AudioChannel()

leftChannel.currentLevel = 7
print(leftChannel.currentLevel)
// Prints “7”
print(AudioChannel.maxInputLevelForAllChannels)
// Prints “7”

rightChannel.currentLevel = 11
print(rightChannel.currentLevel)
// Prints “10”
print(AudioChannel.maxInputLevelForAllChannels)
// Prints “10”

// 위에와는 달리 할당되 새로운 값이 type property에 존재하는 것을 알수 있다.

Classes and Structures

Classes and structures are general-purpose, flexible constructs that become the building blocks of your program’s code. You define properties and methods to add functionality to your classes and structures by using exactly the same syntax as for constants, variables, and functions.

Unlike other programming languages, Swift does not require you to create separate interface and implementation files for custom classes and structures. In Swift, you define a class or a structure in a single file, and the external interface to that class or structure is automatically made available for other code to use.

NOTE

An instance of a class is traditionally known as an object. However, Swift classes and structures are much closer in functionality than in other languages, and much of this chapter describes functionality that can apply to instances of either a class or a structure type.

Comparing Classes and Structures

Classes and structures in Swift have many things in common. Both can:

  • Define properties to store values
  • Define methods to provide functionality
  • Define subscripts to provide access to their values using subscript syntax
  • Define initializers to set up their initial state
  • Be extended to expand their functionality beyond a default implementation
  • Conform to protocols to provide standard functionality of a certain kind

For more information, see Properties, Methods, Subscripts, Initialization, Extensions, and Protocols.

Classes have additional capabilities that structures do not:

  • Inheritance enables one class to inherit the characteristics of another.
  • Type casting enables you to check and interpret the type of a class instance at runtime.
  • Deinitializers enable an instance of a class to free up any resources it has assigned.
  • Reference counting allows more than one reference to a class instance.

For more information, see Inheritance, Type Casting, Deinitialization, and Automatic Reference Counting.

NOTE

Structures are always copied when they are passed around in your code, and do not use reference counting.

Definition Syntax

class keyword and structures with the struct keyword. 

class SomeClass {
   // class definition goes here
}
struct SomeStructure {
   // structure definition goes here
}

NOTE

Whenever you define a new class or structure, you effectively define a brand new Swift type. Give types UpperCamelCase names (such as SomeClass and SomeStructure here). Conversely, always give properties and methods lowerCamelCase names (such as frameRate and incrementCount) to differentiate them from type names.

struct Resolution {
   var width = 0
   var height = 0
}
class VideoMode {
   var resolution = Resolution()
   var interlaced = false
   var frameRate = 0.0
   var name: String?
}

Class and Structure Instances:

let someResolution = Resolution()
let someVideoMode = VideoMode()

Structures and classes both use initializer syntax for new instances. 

Accessing Properties

You can access the properties of an instance using dot syntax.

print(“The width of someResolution is (someResolution.width)”)
// Prints “The width of someResolution is 0”

You can drill down into sub-properties, such as the width property in the resolution property of a VideoMode:

print(“The width of someVideoMode is (someVideoMode.resolution.width)”)
// Prints “The width of someVideoMode is 0”

someVideoMode.resolution.width = 1280
print(“The width of someVideoMode is now (someVideoMode.resolution.width)”)
// Prints “The width of someVideoMode is now 1280”

NOTE

Unlike Objective-C, Swift enables you to set sub-properties of a structure property directly. In the last example above, the width property of the resolution property of someVideoMode is set directly, without your needing to set the entire resolution property to a new value.

Memberwise Initializers for Structure Types

All structures have an automatically-generated memberwise initializer, which you can use to initialize the member properties of new structure instances. Initial values for the properties of the new instance can be passed to the memberwise initializer by name:

let vga = Resolution(width: 640, height: 480)

Unlike structures, class instances do not receive a default memberwise initializer. Initializers are described in more detail in Initialization.

Structures and Enumerations Are Value Types

A value type is a type whose value is copied when it is assigned to a variable or constant, or when it is passed to a function.

You’ve actually been using value types extensively throughout the previous chapters. In fact, all of the basic types in Swift—integers, floating-point numbers, Booleans, strings, arrays and dictionaries—are value types, and are implemented as structures behind the scenes.

(참고 closure is reference type)

All structures and enumerations are value types in Swift. This means that any structure and enumeration instances you create—and any value types they have as properties—are always copied when they are passed around in your code.

let hd = Resolution(width: 1920, height: 1080)
var cinema = hd

cinema.width = 2048

print(“cinema is now (cinema.width) pixels wide”)
// Prints “cinema is now 2048 pixels wide”

print(“hd is still (hd.width) pixels wide”)
// Prints “hd is still 1920 pixels wide”

enum CompassPoint {
   case north, south, east, west
}
var currentDirection = CompassPoint.west
let rememberedDirection = currentDirection
currentDirection = .east
if rememberedDirection == .west {
   print(“The remembered direction is still .west”)
}
// Prints “The remembered direction is still .west”

Classes Are Reference Types

let tenEighty = VideoMode()
tenEighty.resolution = hd
tenEighty.interlaced = true
tenEighty.name = “1080i”
tenEighty.frameRate = 25.0

let alsoTenEighty = tenEighty
alsoTenEighty.frameRate = 30.0

print(“The frameRate property of tenEighty is now (tenEighty.frameRate)”)
// Prints “The frameRate property of tenEighty is now 30.0”

Identity Operators

Because classes are reference types, it is possible for multiple constants and variables to refer to the same single instance of a class behind the scenes. (The same is not true for structures and enumerations, because they are always copied when they are assigned to a constant or variable, or passed to a function.)

It can sometimes be useful to find out if two constants or variables refer to exactly the same instance of a class. To enable this, Swift provides two identity operators:

  • Identical to (===)
  • Not identical to (!==)

if tenEighty === alsoTenEighty {
   print(“tenEighty and alsoTenEighty refer to the same VideoMode instance.”)
}
// Prints “tenEighty and alsoTenEighty refer to the same VideoMode instance.”

  • “Identical to” means that two constants or variables of class type refer to exactly the same class instance.
  • “Equal to” means that two instances are considered “equal” or “equivalent” in value, for some appropriate meaning of “equal”, as defined by the type’s designer.

Assignment and Copy Behavior for Strings, Arrays, and Dictionaries

In Swift, many basic data types such as String, Array, and Dictionary are implemented as structures. This means that data such as strings, arrays, and dictionaries are copied when they are assigned to a new constant or variable, or when they are passed to a function or method.

This behavior is different from Foundation: NSString, NSArray, and NSDictionary are implemented as classes, not structures. Strings, arrays, and dictionaries in Foundation are always assigned and passed around as a reference to an existing instance, rather than as a copy.

NOTE

The description above refers to the “copying” of strings, arrays, and dictionaries. The behavior you see in your code will always be as if a copy took place. However, Swift only performs an actual copy behind the scenes when it is absolutely necessary to do so. Swift manages all value copying to ensure optimal performance, and you should not avoid assignment to try to preempt this optimization.

original source : http://www.androiddocs.com/design/wear/structure.html#2DPicker

Contextual card in the stream:

  • Bridged notifications    mobile 기기에서 notification이 전달된경우
  • Contextual notifications      such as an exercise card that appears when you begin running, are generated locally on the wearable and appear at contextually relevant moments. You can do more with this kind of card than with a notification bridged from the handheld.

Full screen UI app:

Actions

For actions on each card, use the Action cards pattern.

Making Fast

Here are a few of our favorite tips about how to make the 2D picker really fast for your users:

  • Minimize the number of cards
  • Show the most popular card at the top
  • Keep the cards extremely simple
  • Optimize for speed over customization

Exiting

Your app should dismiss the 2D picker when the user makes a selection. Users should also be able to exit by swiping the first card down, or swiping left to right on a left-most card.

Breaking out of the card (with custom layouts)

There are some things you can’t do on a card. Swiping in many directions on a map or controlling a game with a joystick are a couple examples. In those cases it might be good idea to momentarily go full screen.

A typical user experience with a full screen app on Android Wear looks like this:

Automatically exiting

사용자가 작업을 마치고 종료하는 경우를 automatically exiting 이라고 한다.Many devices don’t have back or home buttons. 그러므로 일정 작업이 끝나면 종료해야한다는 것을 명심해야 한다.

Manually exiting

사용자가 스스로 명시적으로 exit하는 경우를 말한다. 사용자가  

long-press 하면 exit을 원하는 것으로 간주해야 한다. 

DismissOverlayView을 이용하여 빠져나간다.