Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

연산 프로퍼티 & 프로퍼티 옵저버 #51

Closed
Youngminah opened this issue Oct 13, 2021 · 0 comments
Closed

연산 프로퍼티 & 프로퍼티 옵저버 #51

Youngminah opened this issue Oct 13, 2021 · 0 comments
Labels

Comments

@Youngminah
Copy link
Owner

class BMI {
   typealias BMIValue = Double

   var userName: String 
   var userWeight: BMIValue
   var userHeight: BMIValue

   var BMIResult: String {
      get {
         let bmiValue = (userWeight * userWeight)/ userHeight
         let bmiStatus = bmiValue < 18.5 ? "저체중" : "정상 이상"
         return "\(userName)님의 BMI 지수는 \(bmiValue)으로, \(bmiStatus)입니다."
      }
      set {
         userName = newValue
      }
   }

   init(userName: String, userWeight: Double, userHeight: Double){
      self.userName = userName
      self.userWeight = userWeight
      self.userHeight = userHeight
   }
}

let bmi = BMI(userName: "JACK", userWeight: 50, userHeight: 160)

bmi.BMIResult = "Minsu" //  Minsu님의 BMI 지수는 15.625으로, 저체중입니다.
  • set만 사용 불가능
  • get 만 사용 가능 또는 둘다 사용
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant