This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
/** | |
Esta función toma 4 parámetros. Los dos primeros son dos enteros que se suman y los dos últimos dos enteros que se multiplican. | |
Los resultados de estas dos operaciones son luego restados. | |
- parameter s1: un entero a sumar. | |
- parameter s2: otro entero a sumar. | |
- parameter m1: un entero a multiplicar. | |
- parameter m2: otro entero a multiplicar. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DosMasDos { | |
// properties | |
let cuantoEs: String // propiedad constantes | |
var respuesta: String? // propiedad opcional, a nil en principio | |
// init | |
init(cuantoEs: String){ // inicializando una de las propiedades, cuando se inicialice la instancia va pedir este valor | |
self.cuantoEs = cuantoEs | |
} | |
// method | |
func preguntaElNinio(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Leguas { | |
var longitudEnLeguas: Double | |
init(_ leguas: Double){ | |
longitudEnLeguas = leguas | |
} | |
init(desdeMillas millas:Double) { | |
longitudEnLeguas = millas / 3 | |
} | |
} | |
var deMillasALeguas = Leguas(desdeMillas: 9.87) // Prints 3.29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Password { | |
var text: String | |
var response: String? // ningún valor TODAVÍA, en principio a ´nil´ | |
init(text:String){ | |
self.text = text | |
} | |
func ask(){ | |
print(text) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Notas diatónicas | |
enum NotasDiatonicas: String { | |
case c = "Do" // hash value "0", raw value "Do" | |
case d = "Re" | |
case e = "Mi" | |
case f = "Fa" | |
case g = "Sol" | |
case a = "La" | |
case b = "Si" // hash value "6", raw value "Si" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fibra { | |
var color: String? | |
var cantidad = 1 | |
var esNueva = false | |
} | |
let miFibra = Fibra() // default initializer | |
miFibra.esNueva // prints "False" | |
miFibra.cantidad // prints "1" | |
miFibra.color = "Azul" | |
print(miFibra.color ?? "Indeterminado") // prints "Azul" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Arduino { | |
// properties without default value | |
var model: String | |
var microcontroller: String | |
var digitalIOPins: Int | |
} | |
let myArduino = Arduino(model: "Yún", microcontroller: "ATmega32U4", digitalIOPins: 20) // memberwise initializer | |
myArduino.model // prints "Yún" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let termo = ["color": "plateado"] | |
func color(of termoColor: [String: String]) { | |
if let color = termoColor["color"] { | |
print("El termo es color \(color)") | |
} else { | |
print("color indeterminado") | |
} | |
} | |
color(of: termo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func teLosDoy() { | |
necesitoDosNumerosParaMultiplicar(n1: 4, n2: 7) // pasa los argumentos a la func 'necesitoDosNumerosParaMultiplicar' | |
} | |
func necesitoDosNumerosParaMultiplicar(n1: Float, n2: Float) { | |
let resultado = n1 * n2 | |
imprimoElResultado(queEs: "\(resultado)") // pasa los argumentos a la func 'imprimoElResultado' | |
} | |
func imprimoElResultado(queEs: String) { |
OlderNewer