HypeDitto / iOS-Study

iOS 기술 면접 대비
0 stars 0 forks source link

some 키워드에 대해 설명하시오. #74

Open YouHojoon opened 1 year ago

YouHojoon commented 1 year ago
HeegeePark commented 1 year ago

불투명한 타입?

protocol Shape {
    func describe() -> String
}

struct Square: Shape {
    func describe() -> String {
        return "I'm a square. My four sides have the same lengths."
    }
}

struct Circle: Shape {
    func describe() -> String {
        return "I'm a circle. I look like a perfectly round apple pie."
    }
}

위와 같은 Shape란 프로토콜과 Shape를 따르는 여러 도형이 있다고 했을 때

func makeShape() -> Shape {
  return Circle()
}

해결 방법

func makeShape() -> some Shape {
  return Circle()
}