Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. // MARK: var, let 이해
  2. let numOfEyes = 2
  3. var fisrtName = "John"
  4.  
  5.  
  6. // MARK: Array, Dictionary 이해
  7. let scores: [Int] = [56, 92, 100, 80]
  8. let firstScore = scores[0]
  9.  
  10. let libraryInfo: [String: Any] = ["name": "Coffee and Library", "price": 12000, "location": "Bundang"]
  11. let libaryName = libraryInfo["name"]
  12.  
  13.  
  14.  
  15. // MARK: 조건문
  16. if firstScore > 90 {
  17. print("you are very smart")
  18. } else {
  19. print("you are smart, too")
  20. }
  21.  
  22.  
  23. let nameKey = "name"
  24. let priceKey = "price"
  25. let locationKey = "location"
  26.  
  27. var anyKey = nameKey
  28. switch anyKey {
  29. case nameKey:
  30. print("value is \(libraryInfo[anyKey])")
  31. case priceKey:
  32. print("value is \(libraryInfo[anyKey])")
  33. case locationKey:
  34. print("value is \(libraryInfo[anyKey])")
  35. default:
  36. print("there is no such a key in dictionary")
  37. }
  38.  
  39. // MARK: 반복문
  40. // print all scores
  41. for score in scores {
  42. print("score is \(score)")
  43. }
  44.  
  45.  
  46. // MARK: Class
  47. class Student {
  48. var score: Int
  49. var name: String
  50.  
  51. init(score: Int, name: String) {
  52. self.score = score
  53. self.name = name
  54. }
  55.  
  56. func printScore() {
  57. print("my score is \(score)")
  58. }
  59.  
  60. func nameAndSchool() -> String {
  61. return "my name is \(name), I'm a student of XX univ."
  62. }
  63. }
  64.  
  65. // MARK: Struct
  66. struct Book {
  67. let author: String
  68. let title: String
  69. let price: Int
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement