Advertisement
Guest User

touples

a guest
Sep 22nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.62 KB | None | 0 0
  1. //functions
  2.  
  3. //simple function
  4. func sayHI(){
  5.     print ("Hello world !!")
  6. }
  7.  
  8. //sayHI()
  9.  
  10.  
  11. //function with argumnts
  12. //java sayHello(String name, String city)\
  13. func sayHello(name:String, city:String){
  14.    print ("hello \(name) from \(city)")
  15. }
  16.  
  17. //call function with args
  18. //java - sayHello("faiz","Haifa")
  19. //sayHello(name:"Faiz",city:"Haifa")
  20.  
  21.  
  22. //function with return value
  23. func giveFive()->Int{
  24.     return 5
  25. }
  26.  
  27. //print (giveFive())
  28.  
  29. //function with args and return value, without naming the args
  30. func pow2(_ number:Int)->Int{
  31.     return number*number
  32. }
  33. //print (pow2(5))
  34.  
  35. typealias personTuple = (name:String, computer:String, age:Int, married:Bool)
  36.  
  37. var myTuple:personTuple = (name:"Michel", computer:"I9", age:26, married:false)
  38. print (myTuple)
  39. func youngAndMarried(oldPerson:personTuple)->personTuple
  40. {
  41.     var youngPerson = oldPerson
  42.     youngPerson.age = 18
  43.     youngPerson.married = true
  44.     return youngPerson
  45. }
  46. print ("-------------------")
  47. print (myTuple)
  48. print (youngAndMarried(oldPerson: myTuple))
  49. print (myTuple)
  50.  
  51. typealias binaryOptions = (name:String, invest:Double, leverage:Int, profit:Int)
  52.  
  53. var michel:binaryOptions = (name:"Michel", invest:1000000, leverage:10, profit:90)
  54.  
  55. print (michel)
  56.  
  57. typealias studentData = (avg:Double, min:Int, max:Int)
  58. func studentsData()-> studentData {
  59.    
  60.  
  61.     return (avg:90, min:90, max:100)
  62. }
  63.  
  64. print (studentsData().max)
  65.  
  66.  
  67. var bestStudents = ("Neo","Neven")
  68. var firstBest = bestStudents.0
  69. var secondBest = bestStudents.1
  70.  
  71. print (secondBest)
  72.  
  73.  
  74. print ("======================================")
  75. michel.invest = 100000000
  76. print (michel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement