gpt4 book ai didi

ios - readwrite 和 readonly 互斥

转载 作者:行者123 更新时间:2023-11-28 13:03:20 25 4
gpt4 key购买 nike

我怎样才能实现这一目标

  • 类中的内部实现必须读写属性

  • 对于类实例的外部交互,属性必须是只读的

最佳答案

在 Objective-C 中:

我的对象.h

@interface MyObject : NSObject

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

@end

我的对象.m

// Class extension
@interface MyObject ()

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

@end

@implementation MyObject

...

在 Swift 中:

class MyObject {

private(set) var myProperty: String

...

关于ios - readwrite 和 readonly 互斥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33360868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com