简体   繁体   中英

readwrite and readonly mutually exclusive

How can I go about achieving this

  • Property has to be readwrite for inner implementation in class

  • Property has to be readonly for external interaction to instances of the class

In Objective-C:

MyObject.h

@interface MyObject : NSObject

@property (nonatomic, readonly, strong) NSString *myProperty;

@end

MyObject.m

// Class extension
@interface MyObject ()

// Redeclare property read-write
@property (nonatomic, readwrite, strong) NSString *myProperty;

@end

@implementation MyObject

...

In Swift:

class MyObject {

    private(set) var myProperty: String

    ...

Try like the following example

In your .h:

@property(nonatomic, retain, readonly) NSDate* theDate;

In your .m:

@interface TheClassName()
@property(nonatomic, retain, readwrite) NSDate* theDate;
@end

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