Skip to content

Commit ec359be

Browse files
committed
Swift
1 parent 300977b commit ec359be

File tree

2 files changed

+77
-11
lines changed

2 files changed

+77
-11
lines changed

Roadmap/15 - ASINCRONÍA/swift/pedroomar23.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,29 @@ import Foundation
2020
* finalizado.
2121
*/
2222

23-
func startProgram(_ name: String, duration: Double) async {
24-
let iniciar = Date()
25-
let terminacion = Date()
23+
func starProgram(_ name: String, duration: Double) async {
24+
let iniciarProgram = Date()
25+
let finishPrgrom = Date()
26+
2627
let formatter = DateFormatter()
2728
formatter.dateFormat = "HH:mm:ss"
28-
29-
print("El programa dio comienzo a \(formatter.string(from: iniciar))")
30-
29+
30+
print("El programa tiene como nombre \(formatter.String(from: iniciarProgram))")
31+
3132
do {
32-
try await Task.sleep(for: .seconds(duration))
33+
try await Task.slepp(from: .seconds(duration))
3334
} catch {
34-
print("Se ha encontrado un error en la ejecucion \(error.localizedDescription)")
35+
print("Ha ocurrido un error a la hora de obtener la duracion \(error.localizedDescription)")
3536
}
36-
37-
print("El programa tuvo su conclusion \(formatter.string(from: terminacion))")
38-
print("El programa tuvo una duracion de \(duration)")
37+
38+
print("El programa de nombre \(name) tuvo una duracion de \(duration)")
3939
}
4040

41+
let newProgram = starProgram("Games", duration: 1)
42+
print(newProgram)
43+
44+
45+
4146

4247

4348

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import Foundation
2+
3+
/*
4+
* EJERCICIO:
5+
* Utilizando tu lenguaje, explora el concepto de expresiones regulares,
6+
* creando una que sea capaz de encontrar y extraer todos los números
7+
* de un texto.
8+
*
9+
* DIFICULTAD EXTRA (opcional):
10+
* Crea 3 expresiones regulares (a tu criterio) capaces de:
11+
* - Validar un email.
12+
* - Validar un número de teléfono.
13+
* - Validar una url.
14+
*/
15+
16+
func textExample() {
17+
let text = """
18+
La serie Naruto tiene 987 capitulos, con 2 temporadas. La serie fue vista en su
19+
estrenos por millones de personas en cerca de mas de 50 paises. Cada temporada conto con 456 capitulos con una
20+
duracion de 20 minutos cada uno.
21+
"""
22+
do {
23+
let serie = try Regex("[0-5]")
24+
} catch {
25+
print("Se ha encontrado un error al extraer los numeros \(error.localizedDescription)")
26+
}
27+
}
28+
29+
let newSerie = textExample()
30+
print(newSerie)
31+
32+
// Extra
33+
func validEmail(email: String) -> Bool { // Validar Email
34+
return email.hasSuffix("@gmail.com")
35+
}
36+
let newEmail = validEmail(email: "@yahoo.com")
37+
print(newEmail)
38+
39+
func validNumber(numero: Int) -> Bool { // Validar numero de telefono
40+
return numero != 50987654
41+
}
42+
let newNumero = validNumber(numero: 564356785678)
43+
print(newNumero)
44+
45+
func validUrl(url: String) -> Bool {
46+
return url.hasSuffix("www.google.com")
47+
}
48+
let newUrl = validUrl(url: "www.yahoo.com")
49+
print(newUrl)
50+
51+
func validTodo(email: String, numero: Int, url: String) -> Bool { // Validar Todo
52+
return validEmail(email: email) && validNumber(numero: numero) && validUrl(url: url)
53+
}
54+
let new = validTodo(email: "@yahoo.com", numero: 65789065, url: "www.yahoo.com")
55+
print(new)
56+
57+
58+
59+
60+
61+

0 commit comments

Comments
 (0)