对 Obj-C 非常陌生,对 .h 和 .m 文件的语法非常困惑。我要做的就是将一个数组传递给我的初始化程序。我的 .h 文件显示错误,Expected a type
而 .m 文件显示警告Conflicting parameter types in implementation of initWithColor': '__strong id' vs 'GLKVector4' (aka 'union _GLKVector4')
平方.h
#import <Foundation/Foundation.h>
@interface Square : NSObject
- (id) initWithColor : (GLKVector4) col;
@end
平方米
#import "Square.h"
#import <GLKit/GLKit.h>
#define BG_WIDTH 500.0f
#define BG_HEIGHT 400.0f
typedef struct {
GLKVector3 positionCoordinates;
GLKVector2 textureCoordinates;
GLKVector3 normalCoordinates;
} VertexData;
VertexData bgRect[] = {
{ { 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, }, // 2D - forward facing only
{ { BG_WIDTH, 0.0f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f} },
{ { 0.0f, BG_HEIGHT, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f} },
{ { 0.0f, BG_HEIGHT, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f} },
{ { BG_WIDTH, 0.0f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f} },
{ { BG_WIDTH, BG_HEIGHT, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f} },};
@implementation Square {
GLKVector4 color;
}
- (id) initWithColor : (GLKVector4) col {
self = [super init];
if (self) {
color = col;
}
return self;
}
@end