Ios 使用方法和属性之间有什么区别?

Ios 使用方法和属性之间有什么区别?,ios,properties,readonly,Ios,Properties,Readonly,我正在研究Elements示例应用程序的源代码,我发现其中有四个属性声明为只读: @property (readonly) UIImage *stateImageForAtomicElementTileView; @property (readonly) UIImage *flipperImageForAtomicElementNavigationItem; @property (readonly) UIImage *stateImageForAtomicElementView; @proper

我正在研究Elements示例应用程序的源代码,我发现其中有四个属性声明为只读:

@property (readonly) UIImage *stateImageForAtomicElementTileView;
@property (readonly) UIImage *flipperImageForAtomicElementNavigationItem;
@property (readonly) UIImage *stateImageForAtomicElementView;
@property (readonly) CGPoint positionForElement;
在实现文件中,它们看起来像

- (UIImage *)stateImageForAtomicElementTileView {
    return [UIImage imageNamed:[NSString stringWithFormat:@"%@_37.png",state]];
}
你能详细说明这样做的原因吗?为什么不使用类似于

- (UIImage*) stateImageForAtomicElementTileView;

在头文件中,然后像[element StateMageForAtomiceLementTileView]一样访问它;与其选择element.stateMageforatomicelementtileview?

不如选择一种习惯用法,因为它们可以以相同的方式使用。这更多的是一个语义问题

一个类既有数据又可以对所述数据执行操作。我认为你应该考虑使用一处房产,并拥有。access而不是[]更多地作为记录stateImageForAtomicElementTileView用途的一种方式


这是一个图像,是类的一部分事实不是从资源动态生成的,应该被视为一个实现细节

很好,我很满意这个答案: