WWDC15

Nov 1, 2015


104: Whats new in Xcode

  1. App Thinning
    • Bitcode
    • Slicing
    • On Demand Resources
  2. Debugging and Profiling Tools
    • Location Instrument
    • Metal System Trace
    • Address Sanitizer

106: Whats new in swift

  1. Recursive enum can marked ‘indirect’

  2. Error Handling

401: Swift and Objective-C Interoperability

403: Improving your Existing Apps with Swift

404: App Thinning in Xcode

App Slicing

  1. Executable Code(armv7, armv7s, arm64)
  2. Resources(image, Metal, OpenGL, Audio, Other Data)
  3. Named Data
    • Store arbitrary file content
    • Classify according to hardware capabilities
    • Use NSDataAsset class to retrieve content in your application

On Demand Resources

  • Asset packs are built by Xcode
  • Can contain any non-executable assets Hosted by the App Store
  • Downloaded when needed
  • Reclaimed as appropriate
  • Device-thinned just like the other content

Build Workflow

  1. Build
    • Xcode Build and Run automatically thins resources for the active run destination.
    • Supported for all simulator and device run destinations.
    • ENABLE_ONLY_ACTIVE_RESOURCES target build setting
  2. Distributing Thinned Applications
    • App Store Purchase
    • TestFlight
    • Ad-hoc/Enterprise Distribution
    • Xcode Server
  3. Ad-hoc/Enterprise Distribution
    • Export thinned variants for all compatible devices
    • Save for Ad-Hoc/Enterprise with distribution manifest option

Note:

移动网络不能下载大于150M App的官方定义: over-the-air size limits

406: UI Testing in Xcode

  1. UI testing
    • Find and interact with UI elements
    • Validate UI properties and state
  2. UI recording
  3. Test reports
  4. Core Technologies
    • XCTest
    • Accessibility

XCUIApplication

  • Proxy for the tested application
  • Tests run in a separate process
  • Always spawns a new process

407: Implementing UI Designs in Interface Builder

  1. Design Time
    • Stack Views, Dynamic Type(Font body, headline…), Advanced Navigation(option+shift+click),
  2. Build Time
    • XML Documents Build to Nib Files.
    • Loading Storyboards At Run Time.
    • Performance. Nib files loaded on demand.
    • Reuse. Nib files enable reuse.
    • Life cycle. Know when objects are created.
  3. Run Time

414: Building Better Apps with Value Types in Swift

Reference Semantics

Copy When You Need It

  1. Manual Copying
  2. Defensive Copying in Cocoa and Objective-C
    • NSDictionary calls -copy on its keys
    • Property copy attribute provides defensive copying on assignment

Immutability: Cocoa[Touch] has a number of immutable classes

  • NSDate, NSURL, UIImage, NSNumber, etc.
  • Improved safety (no need to use copy)

Value Semantics

  1. Variables Are Logically Distinct
    • Mutating one variable of some value type will never affect a different variable
  2. Value types should implement Equatable

Copies Are Cheap

  1. Copying a low-level, fundamental type is constant time.
    • Int, Double, etc
  2. Copying a struct, enum, or tuple of value types is constant time.
    • CGPoint, etc.
  3. Extensible data structures use copy-on-write
    • Copying involves a fixed number of reference-counting operations
    • String, Array, Set, Dictionary, etc.

A Value Type Can Contain a Reference

  1. Immutable References
    • Use deep equality comparisons(isEqual)
  2. References to Mutable Objects
    • Copy-on-Write

Copy-on-Write

// Mutable Object; NSobject
struct BezierPath {
    private var _path = UIBezierPath()
    
    var pathForReading: UIBezierPath {
        return _path
    }
    
    var pathForWriting: UIBezierPath {
        mutating get {
            _path = _path.copy() as! UIBezierPath
            return _path
        }
    }
}

extension BezierPath {
    var isEmpty: Bool {
        return pathForReading.isEmpty
    }
    
    mutating func addLineToPoint(point: CGPoint) {
        self.pathForWriting.addLineToPoint(point: point)
    }
}

// Uniquely Referenced Swift Objects
// The isKnownUniquelyReferenced(_:) function is useful for implementing the copy-on-write optimization for the deep storage of value types:

class Box<T> {
    let unbox: T
    init(_ value: T) {
        unbox = value
    }
}

class Foo: NSObject {
    var count: Int = 0
}

struct Counter {
    private var _counter = Box(Foo())
    
    mutating func increment() {
        // copy the reference only if necessary
        if !isKnownUniquelyReferenced(&_counter) {
            let old = _counter
            _counter = Box(Foo())
            _counter.unbox.count = old.unbox.count
        }
        
        _counter.unbox.count += 1
    }
    
    var value: Int {
        return _counter.unbox.count
    }
}

718: Building Responsive and Efficient Apps with GCD

  1. Quality of Service Introduction
    • QoS can be specified on Blocks and on queues
    • dispatch_async() automatically propagates QoS
    • Some priority inversions are resolved automatically
    • 在串行队列中添加高优先级的任务,如果当前队列还有低优先级的任务,则会提高队列的整体优先级,直到该任务到达。

  2. GCD Design Patterns with QoS
  3. Threads, Queues, and Run Loops
  4. GCD and Crash Reports