简体   繁体   中英

Does Swift support read-only stored properties in Class Type

In Swift supported read-only computed properties.
Does Swift support read-only stored properties in Class type?
If It does not, Can I have a chance to implement code like read-only property.

In objective-c looks like

interface file:
@property (readonly) NSInteger number

implementation file:
- (void)method {

    // can still access _number property
    _number = 100;
}

Thanks for helping

class MyClass {
    private var _x: Int = 0

    var x: Int {
        get {
            return _x
        }
    }

    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM