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

Intro to Swift

Intro to Swift

Introduction to Apple's Swift programming language for iOS and OSX development. Given at Code & Supply on July 15th, 2014

Justin Reese

July 15, 2014
Tweet

Other Decks in Programming

Transcript

  1. I N T RO TO S W I F T

    C O D E & S U P P LY
  2. M E I N T R O T O S

    W I F T Justin Reese - Code & Supply - Polyglot - iOS baptism by fire - 6 apps. Mostly web views
  3. A G E N D A I N T R

    O T O S W I F T I tell you some C&S stuff I tell you some Swift stuff We discuss as a group - or - We break off into small groups
  4. W H AT ’ S S W I F T

    I N T R O T O S W I F T Apple’s new language - Systems programming - Expressive - REPL - Cocoa/Cocoa Touch backed
  5. H O W D O I S W I F

    T ? I N T R O T O S W I F T Xcode 6 Beta - Now free!! - “The Swift Programming Language”
  6. F O L L O W A L O N

    G I N T R O T O S W I F T
  7. F O L L O W A L O N

    G I N T R O T O S W I F T l l d b - - r e p l
  8. B A S I C S I N T R

    O T O S W I F T l e t g r e e t i n g = “ H e l l o ” v a r n a m e : S t r i n g = “ J u s t i n ” p r i n t l n ( g r e e t i n g + “ ” + n a m e )
  9. B A S I C S I N T R

    O T O S W I F T # i m p o r t < s t d i o . h > # i m p o r t < F o u n d a t i o n / F o u n d a t i o n . h > i n t m a i n ( v o i d ) { N S S t r i n g * g r e e t i n g = @ " H e l l o " ; N S S t r i n g * n a m e = @ " J u s t i n " ; N S S t r i n g * o u t p u t = [ N S S t r i n g s t r i n g W i t h F o r m a t : @ " % @ % @ " , g r e e t i n g , n a m e ] ; N S L o g ( o u t p u t ) ; r e t u r n 0 ; }
  10. B A S I C S I N T R

    O T O S W I F T
  11. B A S I C S I N T R

    O T O S W I F T l e t g r e e t i n g = “ H e l l o ” v a r n a m e : S t r i n g = “ J u s t i n ” p r i n t l n ( g r e e t i n g + “ ” + n a m e )
  12. B A S I C S I N T R

    O T O S W I F T l e t g r e e t i n g = “ H e l l o ” v a r n a m e : S t r i n g = “ J u s t i n ” p r i n t l n ( g r e e t i n g + “ ” + n a m e )
  13. B A S I C S I N T R

    O T O S W I F T l e t g r e e t i n g = “ H e l l o ” v a r n a m e : S t r i n g ? = “ J u s t i n ” p r i n t l n ( g r e e t i n g + “ ” + n a m e )
  14. B A S I C S I N T R

    O T O S W I F T l e t g r e e t i n g = “ H e l l o ” v a r n a m e : S t r i n g ? = “ J u s t i n ” p r i n t l n ( g r e e t i n g + “ ” + n a m e )
  15. B A S I C S I N T R

    O T O S W I F T l e t g r e e t i n g = “ H e l l o ” v a r n a m e : S t r i n g ? = “ J u s t i n ” p r i n t l n ( g r e e t i n g + “ ” + n a m e )
  16. I N T E R P O L AT I

    O N I N T R O T O S W I F T l e t a = 3 , b = 5 p r i n t l n ( “ \ ( a ) t i m e s \ ( b ) i s \ ( a * b ) ” )
  17. C O N S TA N T S I N

    T R O T O S W I F T l e t a = 3 , b = 5 a = 5 / / C o m p i l e e r r o r p r i n t l n ( “ \ ( a ) t i m e s \ ( b ) i s \ ( a * b ) ” )
  18. C O L L E C T I O N

    S I N T R O T O S W I F T v a r p e o p l e = [ “ J u s t i n ” , “ R o m e o ” ] / / A u t o m a t i c a l l y t y p e d p e o p l e + = “ B e n ” v a r d i c t i o n a r y [ “ k e y ” : “ v a l u e ” ] v a r p e o p l e : S t r i n g [ ] = [ “ J u s t i n ” , “ R o m e o ” ] / / E x p l i c i t l y t y p e d p e o p l e + = 2 / / E r r o r
  19. C O N T R O L I N T

    R O T O S W I F T f o r n a m e i n n a m e s { p r i n t l n ( “ H e l l o ” + n a m e ) } f o r ( k e y , v a l u e ) i n d i c t i o n a r y { p r i n t l n ( k e y + “ i s ” + v a l u e ) }
  20. C O N T R O L I N T

    R O T O S W I F T i f a t t e n d e e C o u n t > 1 0 { p r i n t l n ( “ c o o l ” ) } e l s e i f a t t e n d e e C o u n t = = 0 { p r i n t l n ( “ W T F ” ) } e l s e p r i n t l n ( “ m e h ” ) }
  21. C O N T R O L I N T

    R O T O S W I F T s w i t c h a t t e n d e e C o u n t { c a s e > 1 0 : p r i n t l n ( “ c o o l ” ) c a s e 0 : p r i n t l n ( “ W T F ” ) d e f a u l t : p r i n t l n ( “ m e h ” ) }
  22. F U N C T I O N S I

    N T R O T O S W I F T f u n c s a y H i ( w h o : S t r i n g = “ W o r l d ” ) { l e t g r e e t i n g = “ H e l l o ” p r i n t l n ( g r e e t i n g + “ ” + w h o ) } s a y H i ( “ C o l i n ” )
  23. F U N C T I O N S I

    N T R O T O S W I F T f u n c s a y H i ( w h o : S t r i n g = “ W o r l d ” ) - > S t r i n g { l e t g r e e t i n g = “ H e l l o ” r e t u r n g r e e t i n g + “ ” + w h o } p r i n t l n ( s a y H i ( “ C o l i n ” ) )
  24. C L O S U R E S I N

    T R O T O S W I F T l e t g r e e t i n g = { r e t u r n “ H e l l o ” + “ W o r l d ” } p r i n t l n ( g r e e t i n g ( ) )
  25. C L A S S E S I N T

    R O T O S W I F T c l a s s P e r s o n { v a r h o b b i e s = [ “ s o c i a l i z i n g ” ] } c l a s s P r o g r a m m e r : P e r s o n { i n i t ( ) { s u p e r . i n i t ( ) h o b b i e s = [ “ s t a r i n g a t b l a c k s c r e e n s ” ] } } l e t j u s t i n = P r o g r a m m e r ( ) f o r h o b b y i n j u s t i n . h o b b i e s { p r i n t l n ( h o b b y ) }
  26. P R O P E R T Y O B

    S E R V E R S I N T R O T O S W I F T c l a s s P e r s o n { v a r h o b b i e s : A r r a y { w i l l S e t { p r i n t l n ( “ A d d i n g \ ( n e w V a l u e ) , e h ? ” ) } d i d S e t { f o r o l d H o b b y i n o l d V a l u e { p r i n t l n ( “ r e m o v e \ ( o l d H o b b y ) ? ” ) } } } }