Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The ownership in iOS

The ownership in iOS

Yuji Taniguchi

April 20, 2018
Tweet

More Decks by Yuji Taniguchi

Other Decks in Programming

Transcript

  1. fn main() { let x = vec![1, 2, 3]; let

    y = x; println!(“x[0] is {}", x[0]); } This code will be compiling error
  2. fn main() { let x = vec![1, 2, 3]; take(x);

    println!(“x[0] is {}", x[0]); } fn take(v: Vec<i32>) { // do something } This code will be compiling error
  3. fn main() { let mut x = &100; let mut

    y = &mut x; *y += 1; println!(“y is {}", y); } This code will be compiling error
  4. - Making extra copies at runtime - Referencing to unique

    resource - Overhead of reference count Problem Point
  5. Point - Prevents simultaneously accessing to Data - Give programmers

    more control - Add types that can’t be implicitly copied
  6. A1. Supporting a type that can’t copy Q. How does

    swift improve performance? A2. Law of exclusivity
  7. moveonly struct File { let descriptor: Int32 init(filename: String) throws

    { descriptor = Darwin.open(filename, O_RDONLY) } deinit { _ = Darwin.close(descriptor) } }
  8. When we use it? - More memory management - Performance

    tuning - Already know that no needed to copy