Obj-C很新,对.h和.m文件的语法非常混淆。我所要做的就是将一个数组传递给我的初始化程序。我得到一个错误在我的.h文件,上面写着Expected a type
和说Conflicting parameter types in implementation of initWithColor': '__strong id' vs 'GLKVector4' (aka 'union _GLKVector4')
Obj C初始化程序声明
Square.h
#import <Foundation/Foundation.h>
@interface Square : NSObject
- (id) initWithColor : (GLKVector4) col;
@end
Square.m
#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
谢谢,但我已经在我的框架中有GLKit。 – Alex
你读过第二点了吗?它说:“将导入添加到您的头文件#import” –