gpt4 book ai didi

objective-c - 覆盖 Objective-C 中的综合属性好还是坏?

转载 作者:太空狗 更新时间:2023-10-30 03:52:25 25 4
gpt4 key购买 nike

我已经覆盖了一个综合属性,因为我想添加一个 NSAssert。

这样做是可以的(即覆盖)还是被认为是不好的做法?

@synthesize someField;

-(NSString*)someField {
NSAssert(someField != nil,@"someField");
return someField;
}

最佳答案

没关系。来自documentation :

You use the @synthesize keyword to tell the compiler that it should synthesize the setter and/or getter methods for the property if you do not supply them within the @implementation block.

因此,如果您提供它们,那么编译器将使用您的,而不管 @synthesize 指令如何。

关于objective-c - 覆盖 Objective-C 中的综合属性好还是坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1043452/

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