😎
Condicionales y operaciones básicas
Todo lo que aprenderás sobre Swift
Operaciones de asignación y aritmeticas
Comparaciones
Operaciones Ternarias
Operador Nil Coalescing
Rangos
Operadores lógicos
Manipulación de Strings
Strings
Inicialización y mutabilidad
Characters
Índices de Strings
Substrings
Prefijos y Sufijos
Representaciones Unicode
Estructuras de datos
Arrays
Acceder y modificar elementos de un Array
Iterando en Arrays
Conjuntos
Iteraciones y operaciones sobre conjuntos
Diccionarios
Iteración en diccionarios
Sentencias de Control
Ciclo for-in
Ciclo while
Uso de if
Uso de Switch
Switch usando rangos - Interval matching
Switch usando tuplas
Switch con casos compuestos
Sentencias de transferencia de control
Continue y break
Fallthrough
Uso de return y guard
Available en API: Manejo de versiones
Cierre del curso
Cierre del curso y próximos pasos
No tienes acceso a esta clase
¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera
No se trata de lo que quieres comprar, sino de quién quieres ser. Invierte en tu educación con el precio especial
Antes: $249
Paga en 4 cuotas sin intereses
Termina en:
Juan Gabriel Gomila
Aportes 36
Preguntas 1
😎
en inglés stride = a long, decisive step (un paso largo y decisivo/firme) 😉
let hh = 24
let interval = 3
var clocks: [Int: String] = [0:"🕛", 3:"🕒", 6:"🕕", 9:"🕘", 12:"🕛", 15:"🕒", 18:"🕕", 21:"🕘"]
for time in stride(from: 0, to: hh, by: interval) {
if var clock = clocks[time] {
clock += (time < 12) ? " am." : " pm."
print("Hora: \(clock)")
}
}
// Reto
// contar horas del dias partiendo desde 0 hasta 24, solo marque cada 3
let initialTime = 0
let endTime = 24
let intervalTime = 3
var timeCount = 0
print("*********")
for tickMark in stride(from: initialTime, to: endTime, by: intervalTime) {
print("Hour: \(tickMark):00")
}
Many examples of this course shown by teacher, are in “The Swift Programming Language” book in Books Store of Apple.
print("----------------------------")
let hours = 12
let hourInterval = 3
for tickTack in stride(from: 3, through: hours, by: hourInterval) {
print(“tickTack: (tickTack)”)
}
//Ejercicio
for hours in stride(from: 0, to: 25, by: 3)
{
if hours == 0
{
print("12 : 00 am")
}else
{
if hours < 12
{
print("\(hours) : 00 am")
}else
{
if hours - 12 == 0
{
print("12 : 00 pm")
}else
{
print("\(hours - 12) : 00 pm")
}
}
}
}
/*OUTPUT
12 : 00 am
3 : 00 am
6 : 00 am
9 : 00 am
12 : 00 pm
3 : 00 pm
6 : 00 pm
9 : 00 pm
12 : 00 pm
*/
var hoursOfTheDay = 24
let hourInterval = 3
for horas in stride(from: 0, to: hoursOfTheDay, by: hourInterval){
print("horas del dia: \(horas)")
}
let clockHours = 12
let clockMinutes = 60
let clockSeconds = 60
let clockHourInterval = 3
let clockMinuteInterval = 5
for hour in stride(from: 0, to: clockHours, by: 3) {
for minutes in stride(from: 0, to: clockMinutes, by: 5){
for seconds in 0..<clockSeconds{
print("La hora es \(hour):\(minutes):\(seconds)")
}
}
}
//EJERCICIOS
let hour = 0
var minute = 60
for hour in 0..<24 {
for minute in stride(from: 0, to: 60, by: 15) {
print(String(format: "%02d:%02d", hour, minute))
}
}
`
El output:
Código:
var clock = [Int : Int]()
for hour in stride(from: 3, to: 13, by: 3) {
clock[hour] = hour
}
print("""
\(clock[12]!)
\(clock[9]!) ⎿ \(clock[3]!)
\(clock[6]!)
""")
Aquí esta mi reto, sencillo pero seguro ![](
Hice un programa para registrar clientes de lo que llevamos del curso la verdad es que me ha ayudado bastante.
//Un programa para administrar clientes
var clientes = [String]()
while(true){
print("Selecciona una opción")
print("1. Agregar un cliente")
print("2. Actualizar un cliente")
print("3. Eliminar un cliente")
print("4. Mostrar todos los clientes")
print("5. Salir")
print("Selecciona una opción: ", terminator: "")
if let opcion = readLine(){
if opcion == "5"{
break
}
switch opcion {
case "1":
print("Ingrese el nombre de su cliente: ", terminator: "")
if let nombre = readLine(){
clientes.append(nombre)
}
case "2":
print("Ingrese la posición a actualizar: ")
if let posicion = readLine(),
let posicionInt = Int(posicion),
clientes.indices.contains(posicionInt){
print("Ingrese el nombre de la persona a actualizar: ", terminator: "")
if let nombre = readLine(){
print("Se actualizo el cliente \(clientes[posicionInt]) por: \(nombre)")
clientes.insert(nombre, at: posicionInt)
}
}
else{
print("Posición no válida")
}
case "3":
print("Ingresa la posición a eliminar: ", terminator: "")
if let posicion = readLine(),
let posicionInt = Int(posicion),
clientes.indices.contains(posicionInt){
print("Cliente \(clientes[posicionInt]) ah sido eliminado!")
clientes.remove(at: posicionInt)
}
else {
print("Posición no válida")
}
case "4":
for (idx, cliente) in clientes.enumerated(){
print("\(idx+1): \(cliente)")
}
default:
print("Opcion no valida")
}
}
}
Le agregué los grados que ha rotado la manecilla
var militaryClock = 24
let hourInterval = 3
var degreesNeedle = 0
var turnEquivalent: String
for handClock in stride(from: 0, through: militaryClock, by: hourInterval) {
if handClock <= 9 {
var zeroLead = "0"
print(zeroLead, terminator: "")
}
print("\(handClock):00, handclock has rotated \(degreesNeedle)°")
degreesNeedle += 90
}
var hours = 27
let hoursInterval = 3
for hourPlatzi in stride(from: 0, to: hours, by: hoursInterval){
print("\(hourPlatzi)")
}
let hour = 9
let minutes = 60
let minuteInterval = 15
for ticMark in stride(from: 0, to: minutes, by: minuteInterval){
print("\(hour): \(ticMark)")
}
let intervalTime = 1
for tickMark in stride(from: 0, through: 23, by: intervalTime) {
if tickMark < 12 {
print("\(tickMark) AM")
} else {
print("\(tickMark) PM")
}
}```
// si no quiero usar el iterador del for:
for _ in 1...5{
print("Hola mundo!")
}
// si no quiero ir de uno en uno:
for _ in stride(from: 0, to: 5, by: 2){
print("Gaa!")
}
let hours = 24
let hourInterval = 3
for time in stride(from: 0, to: hours, by: hourInterval){
if time >= 12 {
print("\(time):00 pm")
}else{
print("\(time):00 am")
}
}
Quise “simular” un reloj, contando las 24 horas de día contando solo minutos de 5 en 5, espero sirva de aporte para alguien c:
for time in 0..<24{
for currentMinute in stride(from: 0, to: 60, by: 5){
print("\(hour) : \(currentMinute)")
}
hour += 1;
}
for i in stride(from: 0, to: 24, by: 3) {
if i < 12 { print("0\(i) : 00 AM") } else {
print("\(i) : 00 PM" )
}
}
let hours = 24
let hourInterval = 3
var startTime = 0
for time in stride(from: startTime, to: hours, by: hourInterval) {
if time <= 9 {
print("La hora es \(time):00 am")
} else {
print("La hora es \(time):00 pm")
}
}
var interval = 3
var limit = 21
for i in stride(from: 0, through: limit, by: interval){
print(String(format: "%02d", i)+((i<12) ? ":00 am":":00 pm"))
}
Reto del reloj
//Reto hacer un reloj de 24 hrs que solo muestre cada 3
let hourDay = 24
let intervalHour = 3
for clock in stride(from: 0, to: hourDay, by: intervalHour){
print("\(clock) : 00")
}```
//reto
var finalHour = 24
let hoursInterval = 3
for tickMark in stride(from: 0, to: finalHour, by: hoursInterval){
print("\(tickMark) : 00")
}
RETO:
let initialTime = 0
let intervalTime = 3
let endTime = 24
var timeCount = 0
let emojis = ["🕕", "🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚","🕕", "🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚"]
for ticMark in stride(from: initialTime, to: endTime, by: intervalTime) {
print("The hour is: \(ticMark):00 \(emojis[ticMark])")
}
let hours = 24
var startHour = 0
let hourInterval = 3
for tickMark in stride(from: 0, to: hours, by: hourInterval) {
print("hour: \(tickMark)")
}
let am_pm = 12
let minute = 01
let hourInterval = 3
for hourRing in stride(from: 0, to: am_pm, by: hourInterval){
print("0\(hourRing) : 0\(minute)")
}
![](
let day = 24
let hourInterval = 3
for hourMark in stride(from: 0, to: day, by:hourInterval){
if (hourMark < 12){
print("Son las: \(hourMark): 00 am")
}else{
print("Son las: \(hourMark): 00 pm")
}
}```
//Reto de horas
let initialTime = 0
let endTime = 24
let secondTtimeInterval = 3
for hora in stride(from: initialTime, to: endTime, by: secondTtimeInterval){
if hora<12 {
print("Son las \(hora):00am ")
}else if hora == 12{
print("Son las \(hora):00pm")
} else{
print("Son las \(hora-12):00pm")
}
}
let baseUnicodeClock = "1F55"
var validCodeString = baseUnicodeClock + "B"
var validUnicodeScalarValue = Int(validCodeString, radix: 16)!
var validUnicodeScalar = Unicode.Scalar(validUnicodeScalarValue)!
var hourBase = 0
for hour in 0...24 {
hourBase = hour
if hour > 12 {
hourBase = hourBase - 12
}
if hourBase == 0 || hourBase == 12 {
validCodeString = baseUnicodeClock + "B"
} else if hourBase == 11 {
validCodeString = baseUnicodeClock + "A"
} else {
validCodeString = baseUnicodeClock + String(hourBase - 1)
}
validUnicodeScalarValue = Int(validCodeString, radix: 16)!
validUnicodeScalar = Unicode.Scalar(validUnicodeScalarValue)!
for minute in stride(from:0,to: 60,by: 15) {
print("\(hour):\(minute == 0 ? "00" : String(minute)) \(validUnicodeScalar)")
}
}```
var endHour = 26
let minute = 60
let minuteIntervale = 5
let hourIntevarle = 3
for tickMarkHour in stride(from: 0, to: endHour, by: hourIntevarle) {
// print("\(tickMarkHour) : 00")
for tickMarck in stride(from: 0, to: minute, by: minuteIntervale) {
if tickMarkHour <= 9 {
print("\(tickMarkHour) : \(tickMarck) AM")
}else {
print("\(tickMarkHour) : \(tickMarck) PM")
}
}
}
Con un ternario 😎
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?