Это “Плохо” для использования @properties для частных переменных только для преимуществ управления памятью?

Попробуйте этот Отражение C# ссылка.

Примечание я думаю тот BindingFlags. Экземпляр и BindingFlags. Статичный эксклюзивны.

9
задан bentford 10 September 2009 в 23:58
поделиться

3 ответа

An alternative is to keep the property private. You can use the following code (in your .m file) to make the property only accessible within your class:

#import "MyClass.h"

@interface MyClass ()
    @property (retain) NSString* privateString; 
@end

@implementation MyClass

    @synthesize privateString;
    // Your code here

@end

Now you've got the ease of a property, but other classes still can't access it, even if they import your .h file!

23
ответ дан 4 December 2019 в 08:33
поделиться

Properties exist for your convenience. If you don't want other people to use properties that exist in your classes, just don't document them.

2
ответ дан 4 December 2019 в 08:33
поделиться

For public properties I don't think Apple recommends it, because sometimes setting a property to nil can have side effects other than just releasing the variable (KVO notifications, or a custom setter method that does something else).

As for private properties, I'm not too sure. Using a property will only save you a couple of key strokes while coding, but you're also making it slightly more complex and fragile. I favour readability and maintainability over convenience to write, because you'll save time in the long run.

0
ответ дан 4 December 2019 в 08:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: