Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Swift Programming Basics (Part I)

1,092 views

Published on

First steps on new Swift programming language for Apple Mac and iOS

Published in: Software
  • DOWNLOAD THI5 BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THI5 BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Swift Programming Basics (Part I)

  1. 1. El#Lenguaje#de# Programación# Swi$% Alberto#Pacheco# M8Learning#Lab# IT#Chihuahua# Módulo#I# Swi>#Básico# Sesión##2#
  2. 2. 37#
  3. 3. 38#
  4. 4. Tendencias#Lenguajes#(200682015)# 3# Indeed#Job#Trends:#hOp://goo.gl/btI5W3#
  5. 5. 7# WWDC#June#2014#
  6. 6. ¿Qué#es#Swi>?# Swi;$adopts$safe$ programming$paIerns$and$ adds$modern$features$to$ make$programming$easier,$ more$flexible,$and$more$fun.$ 11# Apple#“About#Swi>”#
  7. 7. ¿Qué#es#Swi>?# •  Chris#LaOner,#Apple,#2010# •  Objeccve8C,#Dylan,#JS,#Groovy,# Rust,#Haskell,#Ruby,#Python,#C#,# CLU,#Pascal,#Smalltalk,#etc.# 15#
  8. 8. 24#
  9. 9. 25#
  10. 10. 29#
  11. 11. 30#
  12. 12. 36#
  13. 13. 40#
  14. 14. 41# Step%#2%
  15. 15. 42# Step%#3%
  16. 16. 43#
  17. 17. 44#
  18. 18. 45#
  19. 19. 46#
  20. 20. Hola#Mundo!# 2#
  21. 21. #include <stdio.h>! ! int main( int argc, char **argv )! {! printf("Hola Mundo!n");! return 0;! }! Lenguaje#C# 3#
  22. 22. ! ! ! ! println("Hola Mundo!")! ! ! Swi># 4#
  23. 23. ! ! ! ! println(“Hola Mundo!”)! ! ! Swi># Sin% Punto+y+coma% 5#
  24. 24. ! ! ! ! NSLog(@“Hola Mundo!”);! ! ! ObjecJve8C# Sin%@%de%cadenas% NSString% 6#
  25. 25. Datos#8#Variables# 7#
  26. 26. var precio = 3_519.27 ! Variables# 11#
  27. 27. var precio = 3_519.27 ! precio: Double = 3519.27 ! 12# Variables#
  28. 28. Datos#–#Tipos#de#Datos# 13#
  29. 29. var precio = 3_519.27 ! precio: Double = 3519.27 ! 14#
  30. 30. var edad: Int = 20! var costo: Double = 12.50! var alias: String = “Beto”! var geek: Bool = true! var letra: Character = "á" ! ! Tipos#de#Datos# 19#
  31. 31. var edad = 20! var costo = 12.50! var alias = "Beto"! var geek = true! var letra = "á" ! ! Tipos#de#Datos# 20#
  32. 32. var edad = 20! var costo: Double! var alias! ! “Toda&variable&debe&tener&/po&y&valor& antes&de&ser&usada”& Tipos#de#Datos# 21#
  33. 33. var edad = 20 ✔! var costo: Double ✗ ! var alias ✗! ! error: type annotation missing in pattern! var alias! ^! Tipos#de#Datos# 24#
  34. 34. var edad = 20 ✔! var costo: Double = 1.5 ✔ ! var alias ✗! var frac: Double ✗! No&olvides:& 1)  Inicializar&variable&con&un&valor& 2)  Opcional:&escribir&su&/po&de&dato& Tipos#de#Datos# 25#
  35. 35. Datos#–#Constantes# 26#
  36. 36. let geek = true! ! Constantes# geek: Bool = true ! 27# “Si&no&cambia,&use&let”&
  37. 37. let edad ✗! let edad: Int ✗! # ! ! Constantes# error: type annotation missing in pattern! ! error: 'let' declarations require an initializer expression! 29#
  38. 38. let x: Int ✔ if condition {! x = foo()! } else {! x = bar()! }! use(x)! Constantes# 30#
  39. 39. let edad = 15 ✔ ! # ! ! Constantes# 31# No&olvides:& 1)  Inicializar&constante&con&un&valor&
  40. 40. let edad: Int = 15 ✔ ! # ! ! Constantes# 32# No&olvides:& 1)  Inicializar&constante&con&un&valor& 2)  Opcional:&escribir&su&/po&de&dato&
  41. 41. var edad: Int! let !: 3.1416!: 3.1416! “Si&no&cambia,&use&let”& Constante#o#Variable?# 33# Alt%+%P%
  42. 42. var edad: Int! let !: 3.1416 ✔!: 3.1416 ✔! ! Constante#o#Variable?# Acepta%caracteres% en%UNICODE% 34#
  43. 43. let ! = 3.1416! ! = 0.5 ✗! ! # ! ! Constantes# error: Cannot assign a value to a constant ! 35#
  44. 44. import Darwin! let !: M_PI!: M_PI! ! Constante#π# Constante% Predefinida% 36#
  45. 45. Caso#de#Estudio# 37#
  46. 46. Ejemplo:#Un#Formulario# Qué#hacer#cuando#no#se# capturan#todos#los#valores?# 38#
  47. 47. Números#Mágicos# var edad: Int! ! edad = input()! ! if (edad != -1) {! println(“Tiene ”+edad+” años”)! }! ! NULL,%0,%nil,%+1,%INT_MAX,%etc.% 39#
  48. 48. Valores#Opcionales# 40#
  49. 49. Valores#Opcionales# var edad: Int?! ! edad = input()! ! if edad != nil {! println(String(edad!)+” años”)! }! ! 41#
  50. 50. Valores#Opcionales# var edad: Int?! ! edad = input()! ! if edad != nil {! println(String(edad!)+” años”)! }! ! 42#
  51. 51. Valores#Opcionales# var edad: Int?! ! edad = input()! ! if edad != nil {! println(String(edad!)+” años”)! }! ! 43#
  52. 52. Valores#Opcionales# var edad: Int?! ! edad = input()! ! if edad != nil {! println(String(edad!)+” años”)! }! ! 44# Unwrapping%
  53. 53. OpJonals# “Sólo&el&/po&de&dato&opcional&puede& tener&un&valor&de&nil”& Incluyendo&los&datos&primi/vos& 46#
  54. 54. OpJonals# Incluyendo&los&datos&primi/vos& var nombre: String? = ""! ! var nerd: Bool? = true! ! 47#
  55. 55. OpJonals# “Sólo&el&/po&de&dato&opcional&puede& tener&un&valor&de&nil”& & nil&es&el&valor&de&inicialización&por& default& 48#
  56. 56. OpJonals# var nerd: Bool?! ! ! nerd: Bool? = nil! nil&es&el&valor&de&inicialización&por& default& 49#
  57. 57. OpJonals# var nerd: Bool = nil! ! ! error: ...! NO&se&permite&que&un&/po&de&dato&que& NO&es&opcional&valga&nil 50#
  58. 58. Sentencia#If# 51#
  59. 59. if##sin#(#)# var edad: Int?! ! edad = input()! ! if edad != nil {! println("Tiene (edad!) años")! }! ! Sin%paréntesis%()% 52#
  60. 60. if##con#{#}# var edad: Int?! ! edad = input()! ! if edad != nil {! println("Tiene (edad!) años")! }! ! Obligatorio% usar%{}%siempre% 53#
  61. 61. String#InterpolaJon## var edad: Int?! ! edad = input()! ! if edad != nil {! println("Tiene (edad!) años")! }! ! 54#
  62. 62. Unwrapping#an#OpJonal# var edad: Int?! ! edad = input()! ! if edad != nil {! let tmp = edad!! println(“(12*tmp) meses”)! }! ! Cast%to%Int% 55#
  63. 63. Unwrapping#an#OpJonal# var edad: Int?! ! edad = input()! ! if let tmp = edad {! println(“(12*tmp) meses”)! }! ! 56# NO%CAST%
  64. 64. Rangos#y#sentencia#switch# 57#
  65. 65. Switch# switch edad {! case 0:! println(“Error de captura”)! case 18...30:! println(“Aspirante”)! }! ! NO%break% 58#
  66. 66. switch edad {! case 18...30:! println(“Aspirante”)! default:! println(“Rechazar”)! }! ! RANGO% 59#
  67. 67. ! 18...30! ! ! 18..<30! 18%+%30% 18%+%29% Rangos# 60#
  68. 68. Switch# switch edad {! case 0:! println(“Error de captura”)! case 18...30:! println(“Aspirante”)! }! ! 61# Debe&ser&exhaus/vo,&& contemplar&todos&los&casos&
  69. 69. Switch# switch edad {! case 18...30:! println(“Aspirante”)! default:! println(“Rechazar”)! }! ! 62#
  70. 70. Ciclos# 63#
  71. 71. Ciclos#y#Rangos# for i in 1...4 {! println(i)! }! ! 1! 2! 3! 4! 64#
  72. 72. Ciclos#y#Cadenas# for i in “Swift” {! println(i)! }! ! S! w! i! f! t! 65#
  73. 73. Ciclos#y#Arreglos# for i in [1,1,2,3,5] {! println(i)! }! ! 1! 1! 2! 3! 5! 66#
  74. 74. Ciclos#y#Arreglos# var d = [1,1]! for i in 0...4 {! d.append(d[i]+d[i+1])! }! for x in d { print("(x),") }! ! 1,1,2,3,5,8,13! 67#
  75. 75. Playgrounds# 68#
  76. 76. Playgrounds# 69#
  77. 77. 70#
  78. 78. Playgrounds# 71# for x in 0...100 {! let d = Double(x)! d * sin(d * M_PI/8)! }!
  79. 79. Funciones# 72#
  80. 80. Funciones# func hola(nom: String = “Mundo”) {! println(“Hola (nom)!”)! }! ! 73#
  81. 81. Funciones# func hola(nom: String = “Mundo”) {! println(“Hola (nom)!”)! }! ! > hola()! Hola Mundo!! ! > hola(nom:"Ana")! Hola Ana!! 74#
  82. 82. Funciones# func fib(n:Int) -> Int {! switch n {! case 0, 1:! return 1! default:! return fib(n-1) + fib(n-2)! }! }! ! 75#
  83. 83. Funciones# func fib(n:Int) -> Int {! switch n {! case 0, 1:! return 1! default:! return fib(n-1) + fib(n-2)! }! }! ! fib(7)! ! 21! 77#
  84. 84. Funciones# 1! 2! 3! …! func fib(n:Int) -> Int {! switch n {! case 0, 1:! return 1! default:! return fib(n-1) + fib(n-2)! }! }! for n in 1...9 {! println(fib(n))! } ! 78#
  85. 85. Funciones# sec: [Int] = { 1,2,3,5,8,13,21,34,55 }! func fib(n:Int) -> Int {! switch n {! case 0, 1:! return 1! default:! return fib(n-1) + fib(n-2)! }! }! var sec = [Int]()! for n in 1...9 { sec.append(fib(n)) } ! 80#
  86. 86. Patrones# func fib(n:Int) -> Int {! switch n {! case let x where x<2:! return 1! default:! return fib(n-1) + fib(n-2)! }! }! ! 81#
  87. 87. El#Lenguaje#de# Programación# Swi$% % {#Módulo#1#–#Sesión#2}# Alberto#Pacheco# alberto@acm.org# @beto0303# #

×