No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Computed Properties de sólo lectura

8/27
Recursos

Aportes 18

Preguntas 0

Ordenar por:

Los aportes, preguntas y respuestas son vitales para aprender en comunidad. Regístrate o inicia sesión para participar.

enum Languaje {
    case Spanish, English, French
}
enum Gender{
    case male, female
}
struct Person{
    var name: String
}
struct Gretting{
    var person: Person
    var languaje: Languaje
    var gender: Gender
    var languajeGretting: String{
            switch self.languaje {
            case Languaje.Spanish:
                return "Hola "
            case Languaje.English:
                return "Hello "
            case Languaje.French:
                return "Salut "
        }
    
    }
    var abbreviations: String{
            switch self.gender {
            case Gender.male:
                return languajeGretting + "Mr. \(person.name)"
            case Gender.female:
                return languajeGretting + "Mrs. \(person.name)"
        }
    }
}

let guest = Person(name: "Juana")
let welcomeGretting = Gretting(person: guest, languaje: .French, gender: .female)
welcomeGretting.abbreviations
enum Language{
    case Spanish, English, French
}
struct Person{
    var name : String
}
struct Greet{
    var language : Language
    var person: Person
    var greeting: String {
        switch self.language {
        case .Spanish:
            return "Hola \(person.name)"
        case .English:
            return "Hello \(person.name)"
        case .French:
            return "Salut \(person.name)"
        }
    }
}
let person = Person(name: "Cristian")
let greet = Greet(language: .French, person: person)
greet.greeting
struct Person {
    var firstName : String
    var lastName : String
    var name : String {
        firstName + " " + lastName
    }
}

var persona = Person(firstName: "Luis", lastName: "Rangel")
print(persona.name)

Yo hice esto.
Hice una estructura de una persona. Tiene como propiedades: nombre, idioma que habla, genero, saludo, y una presentación

struct Person{
    var name: String
    var gender: Gender
    var language: String
    var greeting: String {
        switch language {
        case "french":
            return "bonjour"
        case "spanish":
            return "hola"
        case "english":
            return "hello"
        default:
            return "I'm sorry, y can't greeting you"
        }
    }
    var presentation: String{
        var title = ""
        if gender == Gender.man{
            title = "Mr. "
        }else {title = "Mrs. "}
        
        return title + name + " says " + greeting
    }
}

var Bradley = Person(name: "Bradley", gender: Gender.man, language: "french")
struct Greeting{
    var lenguage = String()
    var gender = String()
    var name = String()
    
    var menssage: String {
        return initialGreeting + name
    }
    
    var initialGreeting: String {
        switch lenguage{
        case "spanish":
            let aux = "Hola "
            if gender == "Female" {
                return aux + "Señora "
            }
            return aux + "Señor "
        case "english":
            let aux = "Hello "
            if gender == "Female" {
                return aux + "Lady "
            }
            return aux + "Gentleman "
        case "French":
            let aux = "Bonjour"
            if gender == "Female" {
                return aux + "Madame "
            }
            return aux + "Monsieur "
        default:
            return "Hi "
        }
    }
}

let greeting = Greeting(lenguage: "english", gender: "male", name: "Omar")
greeting.menssage

También pude crear este pequeño código

struct Persona {
    var name : String
    var lastName : String
    var yearOfBirth : Int
}

struct edad{
    var persona: Persona
    var edad : Int {
        return 2022 - persona.yearOfBirth
    }
}

let Andy = edad(persona: Persona(name: "andy", lastName: "Paz", yearOfBirth: 2000))
let Luis = edad(persona: Persona(name: "Luis", lastName: "Paz", yearOfBirth: 2002))
let David = edad(persona: Persona(name: "David", lastName: "Flowrez", yearOfBirth: 2015))


print("Hola \(Andy.persona.name) \(Andy.persona.lastName) tu edad actual es: \(Andy.edad)")
print("Hola \(Luis.persona.name) \(Luis.persona.lastName) tu edad actual es: \(Luis.edad)")
print("Hola \(David.persona.name) \(David.persona.lastName) tu edad actual es: \(David.edad)")

enum lenguajes {
    case español, ingles, frances
}

enum generos {
    case hombre, mujer, sinGenero
}

struct persona {
    var nombre : String
    var apellido : String

}

struct saludo {
    var lenguaje : lenguajes
    var genero : generos
    var Humano : persona
    
    var saludo : String{
        switch lenguaje{
        case .español:
            return "hola \(Humano.nombre) "
        case .ingles:
            return "hi \(Humano.nombre)"
        case.frances:
            return "bongiu \(Humano.nombre)"
        }
    }
}


let saludoPersona = saludo(lenguaje: .ingles, genero: .hombre, Humano: persona(nombre: "andy", apellido: "Paz"))
print(saludoPersona.saludo)
class PCPrice {
    var keyboard = 0.0, mouse = 0.0, display = 0.0, pc = 0.0
    var price:Double {
        return keyboard + mouse + display + pc
    }
}

let myPC = PCPrice()
myPC.keyboard = 10.0
myPC.mouse = 5.0
myPC.display = 100.0
myPC.pc = 150.0
myPC.price
class NumbersCalculator {
    var nums = [Int]()
    
    var sum: Int {
        nums.reduce(0) { x, y in x + y }
    }
    
    var substract: Int {
        nums.reduce(0) { x, y in x - y }
    }
    
    var product: Int {
        nums.reduce(1) { x, y in x * y }
    }
    
    var division: Int {
        nums.reduce(1) { x, y in
            if x == 0 {
                return x
            } else if y == 0 {
                return y
            } else {
                return y / x
            }
        }
    }
}
enum Language {
    case Spanish, English
}
enum Gender {
    case Male, Female
}
struct Greet{
    var personName: String
    var language: Language
    var gender: Gender
    var greeting: String {
        switch self.language {
            case .Spanish:
                return "Hola"
            case .English:
                return "Hello"
        }
    }
    var genderPresentation: String {
        switch self.gender {
            case .Male:
                return self.language == Language.English ? "Mr." : "Sr."
            case .Female:
                return self.language == Language.English ? "Mrs." : "Sra."
        }
    }
    var to: String {
        return "\(greeting), \(genderPresentation) \(personName)"
    }
}
let greet = Greet(personName: "Michael", language: Language.English, gender: Gender.Male)
print("\(greet.to)")
struct Greeting{
    var language = "French" , name = "Sara"
    var personalizedGreeting: String{
        switch language{
                case "Spanish":
                    return "Hola \(name)"
                case "English":
                    return "Hello \(name)"
                case "French":
                    return "Bonjour \(name)"
        default:
            return "Sorry I don't speak that language"
        }
            }
        }
Greeting(language: "Spanish", name: "Messi").personalizedGreeting
enum Gender {
    case male
    case female
}


enum Language {

    case spanish
    case english
    case portuguese
}


struct Gretting  {

    var genderPerson = Gender.male
    var languageChoice = Language.spanish
    var grettingStr: String{
        switch languageChoice {
        case .spanish:
            switch genderPerson {
            case .male:
                return "Buenas tarde Señor "
            default:
                return "Buenas tardes Señorita!!"
            }

        case .english:
            switch genderPerson {
            case .male:
                return "Good afternoon Mr"
            default:
                return "Good afternoon Miss!!"
            }

        default:
            switch genderPerson {
            case .male:
                return "Boa tarde Senhor"
            default:
                return "Boa tarde, Senhorita!!"
            }
        }

    }

}

let grettingExample = Gretting(genderPerson: .female, languageChoice: .portuguese)
grettingExample.grettingStr
enum Language {
    case Spanish, English, Portuguese
}

enum Gender {
    case Male, Female
}

struct Person {
    let name : String
    let gender : Gender
    let language : Language
}

struct Greeting {
    var person : Person
    var message : String {
        switch person.language {
        case .Spanish:
            return "Hola, "
        case .English:
            return "Hello, "
        case .Portuguese:
            return "Oi, "
        }
    }
    var abreviation : String {
        switch person.gender {
        case .Male:
            return "\(message) Mr. \(person.name)"
        case .Female:
            return "\(message) Mrs. \(person.name)"
        }
    }
}

let me = Person(name: "José", gender: .Male, language: .Spanish)
let greeting = Greeting(person: me)
greeting.abreviation
enum Language{
    case spanish, english, french
}

enum Gendre{
    case male, female
}

struct PersonName{
    var name: String
}

struct Greeting{
    var language: Language
    var person: PersonName
    var gendre: Gendre
    var greeting: String{
        switch language {
        case .english:
            return "Hello"
        case .spanish:
            return "Hola"
        case .french:
            return "Bonjour"
        }
    }
    var title: String{
        switch gendre {
        case .male:
            switch language {
            case .spanish:
                return "Señor"
            case .english:
                return "Mister"
            case .french:
                return "Monsieur"
            }
        case .female:
            switch language {
            case .spanish:
                return "Señora"
            case .english:
                return "Miss"
            case .french:
                return "Madmoiselle"
            }
        }
    }
}

var guest = PersonName(name: "Julio")
var prueba = Greeting(language: .spanish, person: guest , gendre: .female)
print("\(prueba.greeting), \(prueba.title) \(guest.name)")

enum Language {
    case Spanish, Portuguese, English
}
enum Gender : String{
    case Men, Women
}
struct Persona {
    let name : String
    var gender : Gender
}
struct Greeting {
    var language : Language
    var persona : Persona
    var greeting : String {
        switch self.language {
        case .Portuguese :
            return "\(self.persona.gender.rawValue == "Men" ? "Benvindo" : "Benvinda") \(self.persona.name)"
        case .Spanish :
            return "\(self.persona.gender.rawValue == "Men" ? "Bienvenido" : "Bienvenida") \(self.persona.name)"
        case .English :
            return "Welcome \(self.persona.name)"
        }
    }
}
var newGreeting = Greeting(language: .Spanish, persona: Persona(name: "Kendall", gender: .Men))
newGreeting.greeting

Hice este código para calcular la distancia que existe entre 2 puntos en un plano cartesiano, ademas del punto medio

struct Point {
    var x : Double = 0.0, y = 0.0
}

struct Line {
    var firstPoint = Point()
    var sencondPoint = Point()
    var middlePoint : Point{
        Point(x: (firstPoint.x + sencondPoint.x)/2, y: (firstPoint.y + sencondPoint.y)/2)
        //Formula para calcular donde se encuentra el punto medio entre los 2 puntos dados
    }
    var distanceBetweenPoints : Double {
        (pow((firstPoint.x - sencondPoint.x), 2) + pow((firstPoint.y - sencondPoint.y), 2)).squareRoot()
        //Formula matematica para calcular la distancia entre 2 puntos en el plano cartesiano
    }
}

let newLine = Line(firstPoint: Point(x: 0, y: 0), sencondPoint: Point(x: 4, y: 10))
newLine.distanceBetweenPoints
newLine.middlePoint

Realicé el ejemplo de un ticket de compra:

struct Product{
    var pruductName:String
    var price:Double
}

struct Ticket{
    var products: [Product]
    var total:Double {
        var _total:Double = 0
        for product in products {
            _total += product.price
        }
        return _total
    }
}
let p : [Product] =
    [Product(pruductName: "PS4", price: 399.99),
     Product(pruductName: "XBOX", price: 499.99),
     Product(pruductName: "SWITCH", price: 299.99)]
let ticket = Ticket(products: p)
ticket.total