Skip to content

Latest commit

 

History

History
84 lines (73 loc) · 3.15 KB

Whats_New_in_Foundation.md

File metadata and controls

84 lines (73 loc) · 3.15 KB

WWDC 2017

Table of Contents

What's New in Foundation - Wednesday

Provided by @mihriminaz Session video and resources: https://developer.apple.com/videos/play/wwdc2017/212/

New Api highlights

Foundation

  • FileProvider communication
  • Improved String <-> NSString range conversion
  • Discrete NSProgress support in NSXPCConnection
  • Copy-on-write in NSArray, NSDictionary, NSSet
  • Data inlining
  • Faster bridging from NSNumber to String

Key paths and KVO

  • Swift 3 had string keypaths #keypath to reach a class's property - @objcMembers

    • No type information
    • Had to be type of Any
    • Wasn't type safe
    • Wasn't fast
  • Swift 4

    • With a backslash directly reach the keypath
    \Kid.age
    \Kid.nickname
    \Kid.friends[0]
    

    Reference type examples

    let age = ben[keyPath: \Kid.age]
    ben[keyPath: \Kid.nickname] = “Ben”
    

    Value type example

    bensParty[keyPath: \.theme] = “Ninja”
    
  • WritableKeypath write directly into value type base

  • ReferenceWritableKeypath write into a reference type base

Encoding & Decoding

  • Codable supports different types like Date, URL Json data, lousy types
  • Codable is both encodable and decodable
  • Supports nested types
  • Supports collections with Codable types
  • Coding protocols:
    • CodingKey protocol -> comment_count for different mapping options
  • Encoding or Decoding Exclusively. Conform to only Encodable or Decodable
  • Rename Properties Using Coding Keys
struct Landmark: Codable {
  var name: String
  var foundingYear: Int
  var location: Coordinate
  var vantagePoints: [Coordinate]

  enum CodingKeys: String, CodingKey {
      case name = "title"
      case foundingYear = "founding_date"

      case location
      case vantagePoints
  }
}

The Philosophy Behind

  • No fatal errors -only for developer mistakes
  • Avoid possible errors on decoding(type mismatch, missing key, missing value, data corruption -during decoding data)/encoding (invalid value)
  • Beyond basic error handling: domain specific validation (like url has to be https - you set a rule!), graph value validation