Swift basic concepts - Functions and Classes
 
  March 7, 2019

 Functions and Classes

            


// Functions
func grettings_void() {
print("Hello World!")
}

func grettings() -> String {
return "Hello World!"
}

func grettings(yourname:String) -> String {
return "Hello \(yourname)"
}

func sum(a:Int,b:Int) -> Int {
return a + b
}

print(grettings_void())
print(grettings())
print(grettings(nombre: "Jorge"))
print(sum(a: 2, b: 3))

// Classes
class Person {
var name : String
var age : Int
  
 init(\_name:String, \_age:Int) {
self.name = \_name
self.age = \_age
}
  
 func grettings() -> String {
return self.name + " says Hi!"
}
}

let person = Person(\_name: "Jorge", \_age: 21)
print("This person is named \(persona.nombre) and is \(persona.edad) years old")
print(person.grettings())