Using Collections Effectively

WWDC 2018

Posted by Den on June 22, 2018 · 4 mins read

Using Collections Effectively

WWDC 2018

Using Collections Effectively

WWDC 2018

The fisrt elements of an array

First element access

The second elements of an array

Second element access

We can make it better!

Simpler

Slices

Copying a slice

Memory allocation usage flow

Eager Functions

Lazy Functions

  • Chained computation
  • Only need part of a result
  • No side effects
  • Avoid API boundaries

Avoid Index Invalidation

Common Pitfall

MultiThreaded Mutable Collections

Use the your own Queue

Forming New collections

Use capacity hints if possible

Value and Reference Collections

ObjC — Swift Bridge Examples

Identifying Bridging Problems

When Bridging Happens

Solution