我有三节课:
AbstractRenderElement
PlaneRenderElement
ButtonRenderElement
Button从Plane继承而Plane从Abstract继承。
我有五个文件:
AbstractRenderElement.h
PlaneRenderElement.h
ButtonRenderElement.h
AbstractRenderElement+Protected.h
和PlaneRenderElement+Protected.h
+Protected.h
文件包含一个Class扩展名,该扩展名被导入到该类本身及其直接子类的.m
文件中。
AbstractRenderElement+Protected.h
导入到AbstractRenderElement.m
和PlaneRenderElement.m
中,并且
PlaneRenderElement+Protected.h
被导入到PlaneRenderElement.m
和ButtonRenderElement.m
中。
现在我的问题是:
PlaneRenderElement
定义了两个属性:
类扩展中的Width
和Height
(因为它是受保护的)。
即使我在Width
的类扩展中定义了Height
和Plane
的访问方式,为什么我仍要在Button的实现中进行合成?
这是我的文件:
AbstractRenderElement.h
@interface AbstractRenderElement : NSObject <RenderElement>
@property(nonatomic, readonly) float* modelMatrix;
@property(nonatomic, readonly) float* viewMatrix;
@property(nonatomic, readonly) float* projectionMatrix;
@property(nonatomic, readonly) float* targetModelMatrix;
@property(nonatomic, readonly, strong) Transform* transform;
//initmethod here
@end
AbstractRenderElement+Protected.h
@interface AbstractRenderElement ()
@property(nonatomic, readwrite) float* modelMatrix;
@property(nonatomic, readwrite) float* viewMatrix;
@property(nonatomic, readwrite) float* projectionMatrix;
@property(nonatomic, readwrite) float* targetModelMatrix;
@property(nonatomic, readwrite) BOOL readyForRendering;
@property(nonatomic, readwrite) MetalRenderData* renderData;
@property(nonatomic, readwrite, strong) Transform* transform;
@end
AbstractRenderElement.mm
#import "AbstractRenderElement.h"
#import "AbstractRenderElement+Protected.h"
@implementation AbstractRenderElement
//initializers, methods etc.
@end
PlaneRenderElement.h
@interface PlaneRenderElement : AbstractRenderElement
@property(nonatomic, readonly) float width;
@property(nonatomic, readonly) float height;
@end
PlaneRenderElement+Protected.h
@interface PlaneRenderElement ()
@property(nonatomic, readwrite) float width;
@property(nonatomic, readwrite) float height;
@end
PlaneRenderElement.mm
#import "PlaneRenderElement.h"
#import "PlaneRenderElement+Protected.h"
@implementation PlaneRenderElement
//initializers, methods etc.
@end
ButtonRenderElement.h
#import <Foundation/Foundation.h>
#import "PlaneRenderElement.h"
@interface RenderButtonV0 : PlaneRenderElement
@end
ButtonRenderElement.mm
#import "ButtonRenderElement.h"
#import "PlaneRenderElement+Protected.h"
@interface RenderButtonV0 ()
//Private Properties of Button
@end
@implementation RenderButtonV0
-(instancetype)initWithButton:(ButtonV0*)button {
self = [super init];
if (self) {
[self setButton:button];
[self setWidth:[[self button] width] / 50.0f]; //crash, unrecognized selector
[self setHeight:[[self button] height] / 50.0f];
}
return self;
}
//Rest of Implementation
答案 0 :(得分:0)
您缺少在实现文件中导入私有属性,因此编译器不会为您合成它们。
您在#import AbstractRenderElement+Protected.h
和AbstractRenderElement.m
中应该有#import PlaneRenderElement+Protected.h in PlaneRenderElement.m
基本规则:您应始终在该类的@implementation
文件中导入该类的扩展名。