坚持学 Swift

//
//  main.swift
//  Ultimate
//
//  Created by Mewlan Musajan on 3/6/21.
//

import Foundation

@propertyWrapper
struct TwelveOrLess {
    private var number: Int
    init() {
        self.number = 0
    }
    var wrappedValue: Int {
        get {
            number
        }
        set {
            number = min(newValue, 12)
        }
    }
}

struct SmallRectangle {
    @TwelveOrLess var height: Int
    @TwelveOrLess var width: Int
}

var rectangle = SmallRectangle()
print(rectangle.width)

rectangle.height = 10
print(rectangle.height)

rectangle.width = 24
print(rectangle.width)

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页