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

Swift: Tuples and Functions

Swift: Tuples and Functions

SwiftCrunch, Krakow, Nov 16, 2014

Antonio Bello

November 16, 2014
Tweet

More Decks by Antonio Bello

Other Decks in Programming

Transcript

  1. Return'mul*ple'values func quotientAndRemainder(# dividend: Int, # divisor: Int) -> (quotient:

    Int, remainder: Int) { let quotient = dividend / divisor return (quotient: quotient, remainder: dividend - divisor * quotient) } let result = quotientAndRemainder( dividend: 59, divisor: 13)
  2. Pass$parameters$to$func/ons$and$ methods func quotientAndRemainder(# dividend: Int, # divisor: Int) ->

    (quotient: Int, remainder: Int) { let quotient = dividend / divisor return (quotient: quotient, remainder: dividend - divisor * quotient) } let params = (dividend: 61, divisor: 7) let result = quotientAndRemainder(params)
  3. Use$cases Collec&ng)parameters)before) func&on)call Without'tuples ... var dividend = 29 ...

    var divisor = 3 ... let result = quotientAndRemainder( dividend: dividend, divisor: divisor)
  4. Use$cases Collec&ng)parameters)before) func&on)call With%tuples var params: (dividend: Int, divisor: Int)

    ... params.dividend = 29 ... params.divisor = 3 ... let immutableParams = params let result = quotientAndRemainder(immutable)