enum case Property

신동준·2022년 4월 27일
0

enum Series

목록 보기
3/7

Swift enum 독특한은 case 에 부여하고싶은 property를 부여시킬수있다는것이다

enum Device {
    
    case iPad6(width:Double, height:Double, weight:Double)
    case iPadAir(width:Double, height:Double, weight:Double)
    case iPadPro(width:Double, height:Double, weight:Double)
    
}

struct AppleDevice {
    var iPhone: Int
    var iPad: Device
}

let myAppleDevice = AppleDevice(iPhone: 13, iPad:.iPadAir(width:540.5, height:700, weight:1.2))

print(myAppleDevice.iPad)

출력값: iPadAir(width: 540.5, height: 700.0, weight: 1.2)

caseProperty 사용가능!

profile
Swift 예비개발자

0개의 댓글